Expo : Cannot load an AV asset from a null playback source

Viewed 33

Hi I was trying to use Expo-AV but keep getting the warning [Unhandled promise rejection: Error: Cannot load an AV asset from a null playback source]

When the sound play function first called it show this warning and dosen't plays but after it when I again recall the function it plays without the warning.

const [sound, setSound] = useState();
const [isPlaying, setIsPlaying] = useState(false);

async function playSound() {
    console.log("Loading Sound");
    const { sound } = await Audio.Sound.createAsync(
      { uri },
      { shouldPlay: true }
    );
    setSound(sound);
    console.log("Playing Sound");
    setIsPlaying(true);
    await sound.playAsync();
    sound._onPlaybackStatusUpdate = (status) => {
      if (status.didJustFinish) {
        setIsPlaying(false);
        console.log("Finished");
      }
    };
  }
<TouchableOpacity onPress={playSound()}> 
  <Text>Play</Text>
</TouchableOpacity>

Is there anyway to play after loading properly.

0 Answers
Related