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. Asynchronous play() for QMediaPlayer
Forum Update on Monday, May 27th 2025

Asynchronous play() for QMediaPlayer

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 302 Views
  • 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.
  • S Offline
    S Offline
    swurl
    wrote on last edited by
    #1

    Currently whenever play() is called on a QMediaPlayer, the application hangs until it connects to the source.

    Is there any way to make this asynchronous?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      swurl
      wrote on last edited by
      #6

      Nevermind, I figured it out...

      So it seems that setSource reasonably expects you to actually have stopped the media beforehand. Doing so and adding a small wait works like a charm and indeed plays it asynchronously!

      Relevant example.

      m_player->stop();
      
          QThread::msleep(100);
      
          m_player->setSource(url);
          m_player->play();
      
      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Which version of Qt are you using ?
        On which platform ?
        What kind of source are you connecting ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #3

          Isn't this thread a duplicate of this one ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          0
          • SGaistS SGaist

            Isn't this thread a duplicate of this one ?

            S Offline
            S Offline
            swurl
            wrote on last edited by
            #4

            @SGaist said in Asynchronous play() for QMediaPlayer:

            Isn't this thread a duplicate of this one ?

            So that was kind of a different issue. That issue was trying to figure out why high-latency streams are causing long hangs. Since I've figured out why (it synchronously waits for the stream), I'm now asking separately if it's possible to do it all async.

            Unfortunately it's really hard for me to replicate in a stable, repeatable environment. However I will try my best...

            This was most recently seen on Qt 6.6.0 on Windows. I have yet to be able to test 6.7.0 or Linux, because replicating high-latency streams at home is a tall task. The high-latency streams come from a specialized FRC environment where there are 4Mbps bandwidth limits on everything, and everything's done through the slow mjpeg format.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #5

              I am wondering whether you should go one level below and maybe first test what you can do with GStreamer directly. You will have a finer control.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • S Offline
                S Offline
                swurl
                wrote on last edited by
                #6

                Nevermind, I figured it out...

                So it seems that setSource reasonably expects you to actually have stopped the media beforehand. Doing so and adding a small wait works like a charm and indeed plays it asynchronously!

                Relevant example.

                m_player->stop();
                
                    QThread::msleep(100);
                
                    m_player->setSource(url);
                    m_player->play();
                
                1 Reply Last reply
                0
                • S swurl has marked this topic as solved on

                • Login

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