expo / playlist-example

https://expo.io/@community/playlist
172 stars 116 forks source link

Background staysActiveInBackground argument for Audio.setAudioModeAsync(mode) #62

Open fbotalla opened 2 years ago

fbotalla commented 2 years ago

The playlist does not keep playing in the background even after changing the Audio Mode.

Audio.setAudioModeAsync({
      allowsRecordingIOS: false,
      staysActiveInBackground: true, <--- Changed this
      playsInSilentModeIOS: true,
      shouldDuckAndroid: true,
      interruptionModeAndroid: InterruptionModeAndroid.DoNotMix,
      playThroughEarpieceAndroid: false
    });

I cloned the project, changed that value and that's all I did.

Is there anything extra that needs to be done in this example to have it work in the background?

Thank you!

Spharian commented 1 year ago

Same issue here. Even when going to the control center on iOS, the video stops playing and onPlaybackStatusUpdate's status isPlaying becomes false.

4lun commented 1 year ago

Potentially you're missing this from your app.json (or app.config.js)

{
  "expo": {
    ...
    "ios": {
      ...
      "infoPlist": {
        ...
        "UIBackgroundModes": [
          "audio"
        ]
      }
    }
  }
}

Source: https://docs.expo.dev/versions/latest/sdk/audio/#playing-or-recording-audio-in-background-ios

Spharian commented 1 year ago

Potentially you're missing this from your app.json (or app.config.js)

{
  "expo": {
    ...
    "ios": {
      ...
      "infoPlist": {
        ...
        "UIBackgroundModes": [
          "audio"
        ]
      }
    }
  }
}

Source: https://docs.expo.dev/versions/latest/sdk/audio/#playing-or-recording-audio-in-background-ios

Well in my case the video pauses also (even when going into the Control Center on iOS), do you think it's linked to this?

4lun commented 1 year ago

Ah I missed that you mentioned video, I'm not sure if background video play is possible with expo-av. Only recently looked at getting audio files to work in the background and this was one of the things we had missing in our project

As an aside, we're already looking at an alternative package for audio due to a potential limitation: expo-av doesn't seem to expose/connect-to any native OS controls (e.g. control centre, lock screen) to show and control the currently playing media, which is a deal breaker for us