Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gsantiago opened this issue Aug 28, 2019 · 29 comments
Closed

Comments

@gsantiago
Copy link

gsantiago commented Aug 28, 2019

🐛 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.

@gsantiago gsantiago added the bug label Aug 28, 2019
@cruzach cruzach changed the title Can't play an audio when the app is already in background - iOS [iOS][Audio] Can't play an audio when the app is already in background Aug 28, 2019
@vikash-gupta
Copy link

Hello @gsantiago , I also faced the same issue that you mentioned. The only workaround I found is to keep the screen awake pro-grammatically, however as soon as user locks the screen, next audio doesn't start.

Did you find any workaround?

@gsantiago
Copy link
Author

@vikash-gupta I have disabled the background audio in iOS for now.

@vikash-gupta
Copy link

Bumping this up... Can anyone please look into it?

@alexandermckay
Copy link

Would love to see this resolved.

@spdaly
Copy link

spdaly commented Jan 13, 2020

+1

1 similar comment
@AlexisChup
Copy link

+1

@AlexisChup
Copy link

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

@wanghoppe
Copy link

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

@Lyubomyr
Copy link

Is any progress on this issue?

@bbbbighead
Copy link

same issue encountered

@Lyubomyr
Copy link

Lyubomyr commented Apr 22, 2020

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.

@peterkortvel
Copy link

same issue

@gwendall
Copy link

gwendall commented May 13, 2020

+1, any idea @ide ?

@ohsik
Copy link

ohsik commented May 18, 2020

+1 same issue. Any updates on this??

@AwesomeZaidi
Copy link

This is a huge issue

@AwesomeZaidi
Copy link

AwesomeZaidi commented May 30, 2020

Any other known audio players that can handle this functionality in React Native?

@AwesomeZaidi
Copy link

@sjchmiela @cruzach any thoughts here?

@brentvatne
Copy link
Member

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

@ohsik
Copy link

ohsik commented Jun 5, 2020

@brentvatne Wondering if there's a plan to work on this in the near future?

@brentvatne
Copy link
Member

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

@ohsik
Copy link

ohsik commented Jun 5, 2020

@brentvatne Thank you for the response. Hope to see that update soon!

@drsounds
Copy link

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)

@IjzerenHein IjzerenHein assigned IjzerenHein and unassigned sjchmiela and mczernek Jul 24, 2020
@IjzerenHein
Copy link
Contributor

As far as I'm aware, this was due to an issue in expo-av (similar issue was reported here #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.

@IjzerenHein IjzerenHein added the AV label Aug 7, 2020
@sgvolpe1
Copy link

Same issue

@Jonnathangte68
Copy link

same issue. What's the status of this? 👀

@ide
Copy link
Member

ide commented Jul 15, 2021

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.

@jsdaniell
Copy link

With above config my application works fine reproducing on background on iOS simulator:

 Audio.setAudioModeAsync({
      allowsRecordingIOS: false,
      staysActiveInBackground: true,
      playsInSilentModeIOS: true,
    })
"ios": {
      "infoPlist": {
        "UIBackgroundModes": [
          "audio"
        ]
      }
}

@titushartm
Copy link

Im facing a simular problem with "expo-av": "^13.2.1". I try to record audio with my app. When interruption by locking the screen the recording stops. The recording time is still going and after unlocking the screen the recording continues.

UIBackgroundModes: ["audio"]

await Audio.setAudioModeAsync({
            allowsRecordingIOS: true,
            staysActiveInBackground: true,
            interruptionModeIOS: InterruptionModeIOS.DuckOthers,
            playsInSilentModeIOS: true,
            shouldDuckAndroid: true,
            interruptionModeAndroid: InterruptionModeAndroid.DuckOthers,
            playThroughEarpieceAndroid: false,
          });

@kiorq
Copy link

kiorq commented Aug 18, 2024

For those who the background audio works in the background, you may want to check if UIBackgroundModes in both the app.json and Info.plist file. I believe once you have a bare app (you have an ./ios dir) you'll need to update the Info.plist manually as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests