5

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?

hayata_suenaga
  • 642
  • 1
  • 5
  • 16
  • Is the audio autoplay? Browsers generally don't allow audio that autoplays. https://developer.chrome.com/blog/autoplay/ – ethry Aug 29 '22 at 04:34
  • @ethry I apologize if my post was unclear. But the project is a React Native App, not a web app. Still, if you have any suggestions, I would appreciate it if you could share them with me :) – hayata_suenaga Aug 29 '22 at 18:14

1 Answers1

6
import { Audio } from "expo-av"

const sound = new Audio.Sound()

await sound.loadAsync({
    uri: your_audio_url
})

await sound.playAsync()
Mauro Russo
  • 189
  • 1
  • 5
  • 1
    Welcome to stackoverflow! Please explain your answer to make it helpful. https://stackoverflow.com/help/how-to-answer https://stackoverflow.com/tour – ethry Oct 04 '22 at 02:03