How to use QMediaPlayer to play video ?



  • i use QMediaPlayer to play a mp3,it's ok ,but when i play video in QVideoWidget,but it's no audio and video.my code is:
    player = new QMediaPlayer;
    player->setMedia(QUrl::fromLocalFile("C:\11.mp4"));

    videoWidget = new QVideoWidget;
    player->setVideoOutput(videoWidget);
    player->setVolume(50);
    videoWidget->show();
    player->play();

    but when i complie ,DirectShowPlayerService::doRender: Unresolved error code 80040266 is cued ,release or debug are all cued.



  • Based on the filepath of your mp4 I guess that the question is related to Windows. Which version of Qt do you use?

    Most probably the issue is caused because of the codecs. Please have a look at the similar issue for "Qt 4.7.2 and Qt Mobility":https://bugreports.qt-project.org/browse/QTMOBILITY-1461 and try to apply the same solution.



  • oh ,thanks you reply my qusetion,my QT version is 5.0.2 for window(MINGW).please tell me ,QMediaPlayer can play all format's video? when i play a file of mp3,i write c:\22.mp3,so i guess filepath is right, i didn't use QMediaPlayer.so i don't know where is wrong?thank you



  • To avoid the problem of typo you could ask the user the file to open with a file open dialog. There are default dialogs (QFileDialog) for it, so should take a minimum of work. You are able to test the QMediaPlayer that way and check out if it suits your needs.
    Greetz



  • QMediaPlayer* player = new QMediaPlayer;
    QVideoWidget* vw = new QVideoWidget;
    player->setVideoOutput(vw);
    QFile file("test1.avi");
    if(!file.open(QIODevice::ReadOnly))
    qDebug() << "Could not open file";
    player->setMedia(QUrl::fromLocalFile("test1.avi"));
    player->play();
    vwidget->show();
    DirectShowPlayerService::doRender: Unresolved error code 80040218,i want to know wherther QMediaPlayer can play localvideo and web video in windows 7 .


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.