Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using a QByteArray or QBuffer as the source for a QVideoWidget

Using a QByteArray or QBuffer as the source for a QVideoWidget

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DiogenesTheCynic
    wrote on last edited by
    #1

    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)

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved