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. Playing streaming audio with QMediaPlayer?
Qt 6.11 is out! See what's new in the release blog

Playing streaming audio with QMediaPlayer?

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.7k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello.
    I'm writing application to play audio from a network binary stream. Binary data is sent in the packegas of 4KB and stored in the QBuffer object. What I need is for application to be able to start playing audio when stream is still sending data. For example, when I download first 100KB, media players starts playback while buffer continues to expand up to all 5MB of song file. Everything works when I first download file to QBuffer and then call setMedia and play method from the player. But if I want to play music while stream is still working, media player only plays sound to the position when setMedia method was called and then stoppes. Is there any possible ways to make it work like I want to? Thank you.

    Here is a part of code:
    @song = new QBuffer;
    song->open(QIODevice::ReadWrite);
    char buf[4000];
    unsigned int read = 0;
    unsigned int pos = 0;
    stream->seek(0, END_OF_FILE);
    unsigned int len = stream->Tell();

    bool b = true;
    while(pos <= len)
    {
    stream->seek(pos, client::filePosition::BEGIN_OF_FILE);
    read = stream->read(buf,4000);
    if(read == 0) break;
    song->write(buf,read);
    pos += read;

    if(pos > 100000 && b == true)
    {
        b = false;
        mediaPlayer.setMedia(NULL, song);
        mediaPlayer.play();
    }        
    

    }
    @

    stream is a wrapper to binary stream from another PC.

    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