Audio still not playing in background in standalone builds (EAS)

Hi! I’ve migrated my app to use EAS (works great!), but audio still stops playing in my standalone/TestFlight builds if the screen is turned off or the app is backgrounded. My code is pretty straightforward and follows Expo’s instructions:

SDK Version: 42 / Platforms: iOS

app.json:

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

Initialize audio in app:

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

eas.json:

{
  "build": {
    "base": {
      "releaseChannel": "42"
    },
    "release": {
      "ios": {
        "env": {
          "ENVIRONMENT": "production"
        }
      },
      "android": {
        "env": {
          "ENVIRONMENT": "production"
        },
        "buildType": "app-bundle"
      },
      "extends": "base",
      "distribution": "store"
    }
  }
}

Is there something I’m missing? i.e., do I need to set up the infoPlist options in eas.json as well? Thanks in advance for your help!

Hey @btroia, it looks as if you’ve done all the right steps here. We’ll have to try and reproduce this on our end and get back to you.

Cheers,
Adam

Hmm, ok thanks for looking into it. Was hoping to publish my standalone app with this feature working this week! :crossed_fingers:

Hi @adamjnav any update on this issue? Thanks!

Ok, I think I figured out the issue:

If you have an audio clip that is triggered by a timer / animation thread, backgrounding the app or turning off the screen will stop the threads, so the audio clip will stop playing. BUT… if there is any continuous audio already playing in the background (even from another app!), the audio clips will continue to play. :man_shrugging:t2:

So, a hacky solution that seems to work is to always have a silent audio clip playing/looping, which will allow the audio clips in the app (triggered by timers, animation, etc.) to continue playing.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.