1

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.

livindead
  • 63
  • 1
  • 6

2 Answers2

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:

Shamar Yarde
  • 747
  • 1
  • 7
  • 19
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