why QMediaPlayer not work with QCoreApplication under Mac OS X

796 views Asked by At

Qt version is 5.2, QMediaPlayer in below code doesn't work (doesn't play .mp3 audio file):

#include <QCoreApplication>
#include <QMediaPlayer>
#include <QGuiApplication>

int main(int argc, char **argv) 
{
    // QGuiApplication app(argc, argv);
    QCoreApplication app(argc, argv);
    QMediaPlayer *player = new QMediaPlayer(&app);
    player->setMedia(QUrl::fromLocalFile("some_audio_file.mp3"));

    player->play();

    return app.exec();
}

the same code works under windows, but when use QGuiApplication instead, QMediaPlayer will play the audio file.

Below is the .pro file, please NOTE that, 'gui' is used for 'QGuiApplication'.

QT += gui multimedia

CONFIG -= app_bundle
CONFIG += console

TEMPLATE = app
TARGET = test3
INCLUDEPATH += .

# Input
SOURCES += test.cpp
0

There are 0 answers