Set AVAudioSession for WebView

#1

Hi, I’m trying to play a YouTube video in a webview. While I’ve made some progress on many areas, what I’m completely clueless about is how to change the AVAudioSession to Playback, so the phone won’t have to be Unmuted to play the video sound, to comply with standard iOS behavior.

#2

See this issue on react-native-video for context.

https://github.com/react-native-community/react-native-video/issues/98

#3

The AVAudioSession isn’t directly exposed but you might be able to get it into the state you want by using the Expo AV APIs. This might work:

Expo.Audio.setAudioModeAsync({
  allowsRecordingIOS: false,
  interruptionModeIOS: Expo.Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
  playsInSilentLockedModeIOS: true, // the important field
  interruptionModeAndroid: Expo.Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
  shouldDuckAndroid: true,
});

You’ll have to read some source code to figure things out but here are some starting points:
https://github.com/expo/expo-sdk/blob/master/src/Audio.js#L63

#4

I solved the problem for now by putting some silent audio playing on repeat in the background that has the AVAudioSession set correctly

#5

Hi mrloh

My case is very similar to yours… I have a WebView which loads a web app to play live radio streams from the internet. Everything works fine, but I have not been able to listen to the audio once the app is running with the physical MUTE slider button of my iPhone switched to MUTE or OFF.

Any suggestions or code sample are greatly appreciated.

#6

I’m noticing the same behavior. Video played in a WebView on iOS doesn’t play audio unless the mute button is switched off. If anyone has any ideas how to resolve this, that’d be great!