'How to enable expo video sound to play when silent switch is enabled on iPhone on React Native?
So I am trying to have my video play the sound even when the Iphone has its silent switch activated. The docs say to look at the audio docs which I have but am still getting nothing to work. Am I suppose to somehow connect my Video to the expo Audio api to be able to use those controls?
Currently I have this and it is not working:
useEffect(() => {
async function test() {
await Audio.setAudioModeAsync({
playsInSilentModeIOS: true,
});
const playbackObject = new Audio.Sound();
}
test();
});
<Video
ref={video}
style={styles.videoView}
source={{
// uri: 'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4',
uri: 'http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8',
}}
useNativeControls
resizeMode="contain"
isLooping
onPlaybackStatusUpdate={status => setStatus(() => status)}
/>
Solution 1:[1]
You just have to run a silent sound and make it playAsync. It can work
useEffect(() => {
const setAudioMode = async () => {
await Audio.setAudioModeAsync({
staysActiveInBackground: true,
interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
shouldDuckAndroid: false,
playThroughEarpieceAndroid: false,
allowsRecordingIOS: false,
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
playsInSilentModeIOS: true,
})
if (Platform.OS === "ios") {
const playSilentSound = async () => {
const { sound } = await Audio.Sound.createAsync(
require("./assets/silent-sound.mp3")
)
await sound.playAsync()
await sound.pauseAsync()
}
playSilentSound()
}
}
setAudioMode()
}, [])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Coffee |