Important: Please read the Qt Code of Conduct -

Playing streaming audio with QMediaPlayer?

  • 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;
    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;
    pos += read;

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


    stream is a wrapper to binary stream from another PC.

Log in to reply