How to check is sound is disabled on device React Native EXPO ? I tried to check but in the official documentation there is no description of this.
Asked
Active
Viewed 581 times
2 Answers
0
You can try the following:
import { Audio } from 'expo-av';
import React from 'react';
import { Text, View } from 'react-native';
const App = () => {
const audioPlayer = new Audio.Sound();
React.useEffect(() => {
playAudio();
})
async function playAudio (){
try {
await Audio.setIsEnabledAsync(false); // Only added to test what would happen if sound is disabled on device.
await audioPlayer.unloadAsync();
await audioPlayer.loadAsync(require('./assets/alarm1-b238.mp3')); //alarm1-b238.mp3 would be any audio file inside the assets folder.
await audioPlayer.playAsync();
await audioPlayer.stopAsync(); //Since you might not want a sound to play before whatever you want the code to do
} catch(error) {
console.log('error', error); //Should produce an error
}
}
return null;
}
export default App;
References:
- Expo. Audio. https://docs.expo.io/versions/latest/sdk/audio/. (accessed November 22, 2019)
- StackOverflow. React Native - Expo Audio stop all sounds. https://stackoverflow.com/a/51207494/8121551. (accessed November 22, 2019)

Shamar Yarde
- 747
- 1
- 7
- 19
-
@livindead Please accept this answer if it helps you, or indicate if you experience another problem. – Shamar Yarde Nov 30 '19 at 18:14
0
Audio.setIsEnabledAsync(true); is what you would call to disable or enable audio.
It is automatically set to true so you more than likely have an issue with .loadAsync

dbazian
- 15
- 5