expo: [iOS][Audio] Can't play an audio when the app is already in background

🐛 Bug Report

Environment

  Expo CLI 2.19.5 environment info:
    System:
      OS: Linux 5.0 Ubuntu 19.04 (Disco Dingo)
      Shell: 3.0.2 - /usr/bin/fish
    Binaries:
      Node: 10.15.2 - /tmp/yarn--1567012357926-0.5700793194663918/node
      Yarn: 1.16.0 - /tmp/yarn--1567012357926-0.5700793194663918/yarn
      npm: 5.8.0 - /usr/bin/npm
    npmPackages:
      @types/react: ^16.8.19 => 16.8.19 
      @types/react-native: ^0.57.60 => 0.57.62 
      expo: ^34.0.3 => 34.0.4 
      react: 16.8.3 => 16.8.3 
      react-native: https://github.com/expo/react-native/archive/sdk-34.0.0.tar.gz => 0.59.8 
    npmGlobalPackages:
      expo-cli: 3.0.10

This bug only happens in iOS.

Steps to Reproduce

Expected Behavior

  • The app should play the audio when it’s already in background.

Actual Behavior

  • In Android, it works perfectly fine.
  • In iOS, I get the following error:
[Error: Play encountered an error: audio session not activated.]

Reproducible Demo

https://snack.expo.io/@gsantiago/reproducible-bug---failed-to-play-audio-when-the-app-is-in-background

And, yes. I have set staysActiveInBackground: true and all other necessary modes to play in background, and also UBackgroundModes: [‘audio’] in the app.json.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 22
  • Comments: 28 (4 by maintainers)

Most upvoted comments

Is any progress on this issue?

As far as I’m aware, this was due to an issue in expo-av (similar issue was reported here https://github.com/expo/expo/pull/9363)

You should now be able to resume/play audio when in the background when staysActiveInBackground=true is set.

This has not yet landed in the Expo client, but you can try it out in a bare project using:

yarn install expo-av@8.4.0

You can find the changelog here: https://github.com/expo/expo/blob/master/packages/expo-av/CHANGELOG.md

Let us know whether that fixes it for you.

Would love to see this resolved.

i wish we had time to but are pretty busy at the moment with bigger infrastructure improvements because that work will unblock users from solving issues like this for themselves.

if anyone here would like to hire someone to work on this feature for you, i would recommend reaching out to https://swmansion.com/ - we are partners with them and they have a lot of experience at the org with expo and react-native. i would highly recommend them

This is a huge issue

My steps to reproduce:

  1. Use the last version of library.
  2. Use background options for the sound:
    Audio.setAudioModeAsync({
      allowsRecordingIOS: false,
      staysActiveInBackground: true,
      interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
      playsInSilentModeIOS: true,
      shouldDuckAndroid: true,
      interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
      playThroughEarpieceAndroid: true,
      useNativeControls: false
    })

and for app.json:

"ios": {
      "infoPlist": {
        "UIBackgroundModes": [
          "audio"
        ]
      }
}
  1. Play some test video file using the Video from expo-av.

  2. Put application to background. Result: audio plays only on Android, on IOS production, IOS expo app or simulator no sound at all.

  3. Redo the same using the same video file but now Audio from expo-av Result: audio plays on Androind and IOS production (not always), IOS expo app, or simulator no sound at all.

My entire App is about sounds which start when the app is in Background, so it would be wonderful if this feature worked !

+1

This closed issue is two years old and new issues with similar symptoms may have different root causes. The best way to help address a problem is to suss out the cause and write it up in a new issue.

Same issue

Expo should implement an audio playback service in the native expo runtime, eg run not on react native thread which handles playback in bakgrund per default which is communicated over bridge instead of running audio on the ui layer (as now with expo av)

from our managed workflow limitations docs page

Screen Shot 2020-05-30 at 3 34 52 PM

you may need to eject if you want more complete background audio functionality, for now

+1, any idea @ide ?

same issue

same issue encountered

My app is a music player… Now you can only play one song in the background. Looking forward updates