IOS: playing video using QMediaPlayer and QVideoWidget



  • Hi all,

    I've set up a small project in the folder "iosVideoTest/" to play a video in a Qt/iOS app:

    iosVideoTest.pro:
    @
    QT += core gui multimedia multimediawidgets
    QTPLUGIN += qavfmediaplayer
    CONFIG += mobility
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = iosVideoTest
    TEMPLATE = app
    SOURCES += main.cpp
    HEADERS +=
    deployment.files = ../iosVideoTest/media/9d0386eada217cd63a752458aeca89d6.mp4
    deployment.path =
    QMAKE_BUNDLE_DATA += deployment
    @

    main.cpp:
    @
    #include <QApplication>
    #include <QMainWindow>
    #include <QMediaPlayer>
    #include <QUrl>
    #include <QVideoWidget>
    int main(int argc, char argv[]){
    QApplication a(argc, argv);
    QMainWindow w;
    QVideoWidget
    pVWidget = new QVideoWidget;
    QMediaPlayer* pPlayer = new QMediaPlayer;
    // with the following line a video is playing
    pPlayer->setMedia(QUrl("http://www.rmh.de/9d0386eada217cd63a752458aeca89d6/9d0386eada217cd63a752458aeca89d6.mp4"));
    // either of the following lines renders only a black screen
    // pPlayer->setMedia(QUrl::fromLocalFile(QCoreApplication::applicationDirPath() + "9d0386eada217cd63a752458aeca89d6.mp4"));
    // pPlayer->setMedia(QUrl::fromLocalFile("9d0386eada217cd63a752458aeca89d6.mp4"));
    pPlayer->setVideoOutput(pVWidget);
    w.setCentralWidget(pVWidget);
    w.show();
    pPlayer->play();
    return a.exec();
    }
    @

    I've copied the video http://www.rmh.de/9d0386eada217cd63a752458aeca89d6/9d0386eada217cd63a752458aeca89d6.mp4 to the ./media directory in the project folder.

    Using the web URL of the video works (main.cpp line 12).
    However, bundling the video inside the app and using the local file name only renders a black screen (main.cpp lines 14 or 15).

    EDIT: Using an image (located at ./iosVideoTest/media/img.png), bundling it via QMAKE_BUNDLE_DATA and using it as a local file with an QLabel/QPixmap works like a charm …

    Can anybody point me in the right direction to use local video files?

    Regards,
    Tom



  • iOS is diffrent than linux or windows and you can't create directory or copy any file to project folder.

    Look at this thread for more info. It should be clear. "Click!":http://qt-project.org/forums/viewthread/36263/



  • With "project folder" I referred to the directory with my source code. The video gets correctly bundled into the app. However, I cannot play it as a local file. Only with a web URL.

    On the other hand, displaying an image bundled into the app works.



  • Did you try to use resources file? Just create one and add your file to it, and then run it from there.



  • Thanks kolegs, using Qt's resource system works.
    But will that be efficient for videos?



  • Actually I never tried playing any videos on iOS so I got no idea, you have to check it on your own, but I belive it won't be slower then using files. But you can check it, just copy the file from resources @QFile::copy()@ to @"../Documents/@ and run it from there.


Log in to reply
 

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