Using a QByteArray or QBuffer as the source for a QVideoWidget



  • Is this possible? I haven't been able to find much documentation for this online.

    Initial setup:
    @
    QMediaPlayer* mpQMediaPlayer = new QMediaPlayer( 0, QMediaPlayer::StreamPlayback );
    QVideoWidget* mpQVideoWidget = new QVideoWidget;
    mpMediaPlayer->setVideoOutput( mpQVideoWidget );
    @

    File setup:
    @
    // Locate the file
    QString mQFileName( "videos/1.mp4" );
    QUrl qFileUrl( QUrl::fromLocalFile( mQFileName ) );

    // Create the QFile object
    mpQFile* = new QFile( qFileUrl );
    mpQFile->open( QIODevice::ReadOnly );

    // Read the data & put it in a QByteArray
    int filesize = mpQFile->size();
    char* fdata = new char[filesize];
    QByteArray mQByteArray( (const char *)fdata, filesize );
    @

    Using the QBuffer:
    @
    // Create the buffer
    QBuffer mpQBuffer = new QBuffer( &mByteArray, 0 );
    mpBuffer->open( QIODevice::ReadOnly );

    // Create and set the media content
    QMediaContent* mpQMediaContent = new MediaContent( qFileUrl );
    mpQMediaPlayer->setMedia( mpQMediaContent, (QIODevice)mpQBuffer );

    // Start the game already!
    mpQVideoWidget->show();
    mpQMediaPlayer->play();
    @
    (apologies for any small typos)


Log in to reply
 

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