QMediaPlayer setPosition results in a position of 0
-
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(); }
-
connect(this, &QMediaPlayer::mediaStatusChanged, this, &MyPlayer::mediaStatusChanged);
void MyPlayer::mediaStatusChanged(QMediaPlayer::MediaStatus status) { if (status == QMediaPlayer::BufferedMedia) { setPosition(customPosition); } }
-
@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?
-
@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.