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. QMediaPlayer setPosition results in a position of 0

QMediaPlayer setPosition results in a position of 0

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmediaplayerstalledmediamacosmultimedia
5 Posts 3 Posters 942 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
    szumial
    wrote on 13 Jun 2023, 08:19 last edited by
    #1

    Hi! I have a program which uses the QMediaPlayer on MacOS. The logic allows me to set the current position of a local audio file by calling the setPosition function. Everything works fine when I use the functionality for the first time, but when doing it another time, the setPosition does not work. I have debugged it and it shows that the position is set to 0, even though it is getting a correct position argument. This happens regardless of using the same audio file or switching to a new one. Further debugging shows, that consecutive calls to setPosition might not be successful (or at least that is my assumption), because the QMediaPlayer::MediaStatus reports a StalledMedia status.

    I am compiling my program using Qt 6.5.0 and I am using the native darwin multimedia backend on MacOS.

    The same functionality works fine on Windows.

    I looked for similar issues in the threads, but none of them matches my exact problem. I am running out of ideas on why this might be happening and for now it looks like something specific to the used multimedia backend. Unfortunately I cannot switch to another one (for example ffmpeg).

    Here is a minimal code example:

    void MyPlayer::playAudio(const QUrl &url)
    {
        // Set the QUrl which is obtained from a local file
        m_player.setSource(url);
    
        // Set the requested position within the audio track
        // Obtained from a widget that controls the position
        if (customPositionRequested())
        {
            m_player.setPosition(customPosition);
        }
    
        // play audio
        m_player.play();
    }
    
    Z 1 Reply Last reply 13 Jun 2023, 19:08
    0
    • S szumial
      13 Jun 2023, 08:19

      Hi! I have a program which uses the QMediaPlayer on MacOS. The logic allows me to set the current position of a local audio file by calling the setPosition function. Everything works fine when I use the functionality for the first time, but when doing it another time, the setPosition does not work. I have debugged it and it shows that the position is set to 0, even though it is getting a correct position argument. This happens regardless of using the same audio file or switching to a new one. Further debugging shows, that consecutive calls to setPosition might not be successful (or at least that is my assumption), because the QMediaPlayer::MediaStatus reports a StalledMedia status.

      I am compiling my program using Qt 6.5.0 and I am using the native darwin multimedia backend on MacOS.

      The same functionality works fine on Windows.

      I looked for similar issues in the threads, but none of them matches my exact problem. I am running out of ideas on why this might be happening and for now it looks like something specific to the used multimedia backend. Unfortunately I cannot switch to another one (for example ffmpeg).

      Here is a minimal code example:

      void MyPlayer::playAudio(const QUrl &url)
      {
          // Set the QUrl which is obtained from a local file
          m_player.setSource(url);
      
          // Set the requested position within the audio track
          // Obtained from a widget that controls the position
          if (customPositionRequested())
          {
              m_player.setPosition(customPosition);
          }
      
          // play audio
          m_player.play();
      }
      
      Z Offline
      Z Offline
      Zbigniew-Sch
      wrote on 13 Jun 2023, 19:08 last edited by
      #2

      @szumial

      connect(this, &QMediaPlayer::mediaStatusChanged, this, &MyPlayer::mediaStatusChanged);
      
      void MyPlayer::mediaStatusChanged(QMediaPlayer::MediaStatus status)
      {
      	if (status == QMediaPlayer::BufferedMedia)
      	{
      		setPosition(customPosition);
      	} 
      }
      
      S 1 Reply Last reply 13 Jun 2023, 20:43
      0
      • Z Zbigniew-Sch
        13 Jun 2023, 19:08

        @szumial

        connect(this, &QMediaPlayer::mediaStatusChanged, this, &MyPlayer::mediaStatusChanged);
        
        void MyPlayer::mediaStatusChanged(QMediaPlayer::MediaStatus status)
        {
        	if (status == QMediaPlayer::BufferedMedia)
        	{
        		setPosition(customPosition);
        	} 
        }
        
        S Offline
        S Offline
        szumial
        wrote on 13 Jun 2023, 20:43 last edited by
        #3

        @Zbigniew-Sch does the QMediaPlayer have to be in a specific state before calling the setPosition on it? I mean, do I need to call it after calling play(), pause() or stop() first?

        M 1 Reply Last reply 14 Jun 2023, 01:50
        0
        • S szumial
          13 Jun 2023, 20:43

          @Zbigniew-Sch does the QMediaPlayer have to be in a specific state before calling the setPosition on it? I mean, do I need to call it after calling play(), pause() or stop() first?

          M Offline
          M Offline
          mzimmers
          wrote on 14 Jun 2023, 01:50 last edited by
          #4

          @szumial I don't think so. Are you sure your URL is good, and the file it points to is good, too? You might want to look at the duration property as a sanity check that what you're loading is good.

          S 1 Reply Last reply 14 Jun 2023, 06:35
          0
          • M mzimmers
            14 Jun 2023, 01:50

            @szumial I don't think so. Are you sure your URL is good, and the file it points to is good, too? You might want to look at the duration property as a sanity check that what you're loading is good.

            S Offline
            S Offline
            szumial
            wrote on 14 Jun 2023, 06:35 last edited by
            #5

            @mzimmers Yes, I am sure that the url is pointing to the correct source. In fact what seems strange is that the first time I call setPosition it works, but any other time, regardless of the url being identical or changed to point to a different file, it ends up being in the StalledMedia state.

            1 Reply Last reply
            0

            2/5

            13 Jun 2023, 19:08

            • Login

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