react-nativeexpoexpo-av

expo-av how to play audio with URL


I'm working with expo-av package in my Expo managed app.

I'm passing a url to an audio file on the internet to createAsync, but the audio is not playing. When I use an audio file that lives alongside the source code with require(), the audio plays without problem.

  const { sound } = await Audio.Sound.createAsync({uri: url});
  await sound.playAsync();
  await sound.unloadAsync();

Is there any specific steps needed for playing audio on the internet?


Solution

  • import { Audio } from "expo-av"
    
    const sound = new Audio.Sound()
    
    await sound.loadAsync({
        uri: your_audio_url
    })
    
    await sound.playAsync()