I'm trying to play audio through Qt6. But, I've been getting a weird error that I don't know what means or how to deal with. I made a minimal example:
// main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
// mainwindow.cpp
// mostly taken from .html
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
player = new QMediaPlayer(this);
output = new QAudioOutput(this);
player->setAudioOutput(output);
output->setVolume(50);
player->setSource(QUrl::fromLocalFile("C:\\Users\\kmdw\\Downloads\\sample-6s.mp3"));
player->play();
}
MainWindow::~MainWindow() {}
// mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QMediaPlayer>
#include <QAudioOutput>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
QMediaPlayer* player;
QAudioOutput* output;
};
#endif // MAINWINDOW_H
It's supposed to just play the audio as soon as the application starts. Instead, the application starts, a few seconds pass, then it starts spewing out errors without playing any audio. The logs look like this:
These ones look normal, appear as soon as the app starts:
qt.multimedia.ffmpeg: Using Qt multimedia with FFmpeg version 7.1 LGPL version 2.1 or later
qt.multimedia.ffmpeg: Available HW decoding frameworks:
qt.multimedia.ffmpeg: d3d11va
qt.multimedia.ffmpeg: dxva2
qt.multimedia.ffmpeg: Available HW encoding frameworks:
qt.multimedia.ffmpeg: d3d11va
qt.multimedia.ffmpeg: dxva2
These happen a few seconds in and are errors:
[mp3float @ 00000225fb329040] Could not update timestamps for skipped samples.
[SWR @ 00000225fb38f500] Output channel layout "" is invalid or unsupported.
[SWR @ 00000225fb38f500] Context has not been initialized
[SWR @ 00000225fb38f500] Context has not been initialized
[SWR @ 00000225fb38f500] Context has not been initialized
[SWR @ 00000225fb38f500] Context has not been initialized
...
The SWR thing repeats until I close the application.
- OS: Windows 11
- Qt version: Desktop Qt 6.8.2 MinGW 64-bit
- Using Qt Creator
- It's using a bundled FFmpeg version probably because when I moved my own FFmpeg install to the Recycle Bin it still started.
FFplay and Windows media player both play sample-6s.mp3 fine so it's not a problem with the audio file.