iOS Question Background sound stopping when app is in background

Alessandro71

Well-Known Member
Licensed User
Longtime User
Following this example https://www.b4x.com/android/forum/threads/background-playback.49337/ I'm trying to keep playing a sound when the app is sent in background.
Since I only need a sound, and the onscreen page is not always the same, I'm using MediaPlayer instead of VideoPlayer.

So I added
B4X:
#PlistExtra: <key>UIBackgroundModes</key><array><string>audio</string></array>

B4X:
    Public BackgroundSound As MediaPlayer
    BackgroundSound.Initialize(File.DirAssets, "backgroundsound.wav", "BackgroundSound")
    BackgroundSound.Looping = True
    BackgroundSound.Play

The sound starts playing with the app in foreground, but a soon as I press the home button, the sound stops.
Bringing the app back to foreground, causes the sound to resume playing.

What's the correct way to keep playing also when the home screen is displayed?
 
Top