MediaPlayer on iOS stops when playing other sounds
Unsolved
QML and Qt Quick
-
I recently upgraded my project to Qt6.2 and encountered the following problem:
I am using 3 different QML Mediaplayers in my scene, one for background music and two for sound effects:
MediaPlayer { id: playAudioFile1 audioOutput: AudioOutput {} onErrorOccurred: function (error, errorString) { console.info("play AudioPlayer1: Error " + error + ", as string: " + errorString) } onPlaybackStateChanged: console.log("play AudioPlayer1 playbackState changed to: " + playbackState) } MediaPlayer { id: playAudioFile2 audioOutput: AudioOutput {} onErrorOccurred: function (error, errorString) { console.info("play AudioPlayer2: Error " + error + ", as string: " + errorString) } onPlaybackStateChanged: console.log("play AudioPlayer2 playbackState changed to: " + playbackState) } function playSound(soundFile, playerNo = 1, volume = 1.0) { if (soundFile !== "") { var playerToUse = (playerNo === 2) ? playAudioFile2 : playAudioFile1 console.log("play Sound called for " + soundFile + " on Player" + playerNo + " with status: " + playerToUse.playbackState + " and current source: " + playerToUse.source) if (playerToUse.playbackState !== MediaPlayer.PlayingState) { let source = "qrc:/assets/sounds/" + soundFile + ".wav" if (playerToUse.source != source) { console.log("loading new source...") playerToUse.source = source } playerToUse.play() console.log("play Sound: SoundEffect" + playerNo + ": Playing '" + soundFile) } else { console.log("play Sound: SoundEffect" + playerNo + ": Double playing prevented: '" + soundFile) if (playerNo === 1) { console.log("play Sound using player2!") playSound(soundFile, 2, volume) } } } } MediaPlayer { id: themeSong source: "qrc:/assets/sounds/theme.mp3" loops: SoundEffect.Infinite audioOutput: AudioOutput {} onErrorOccurred: function (error, errorString) { console.info("themeSong: Error " + error + ", as string: " + errorString) } } function playTheme(start) { if (start) { console.log("start playing theme") themeSong.play() } else { console.log("stop playing theme") themeSong.stop() } }
This works seamlessly for my Android and MacOS builds, but has a strange behaviour if I am building for iOS/iPad:
- themeSong is playing in a loop
- if playing a sound, that is already set as source in a MediaPlayer, themeSong continue playing
- but if a new source is set, the themeSong just stops playing, no error occurs, neither does the playbackState change nor the mediaStatus
Am I doing something completely wrong here?
Is it intended to use an own MediaPlayer for each different source so that changing it during runtime is not necessary?