Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. MediaPlayer on iOS stops when playing other sounds
Qt 6.11 is out! See what's new in the release blog

MediaPlayer on iOS stops when playing other sounds

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 198 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.
  • SyntaXS Offline
    SyntaXS Offline
    SyntaX
    wrote on last edited by SyntaX
    #1

    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?

    1 Reply Last reply
    0

    • Login

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