c++ - Qt gives errors when playing audio - Stack Overflow

I'm trying to play audio through Qt6. But, I've been getting a weird error that I don't

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744060554a4551705.html

相关推荐

  • c++ - Qt gives errors when playing audio - Stack Overflow

    I'm trying to play audio through Qt6. But, I've been getting a weird error that I don't

    9天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信