Trying to get Audio files to play with expo-av

Please provide the following:

  1. SDK Version: ^47.0.13
  2. Platforms(Android/iOS/web/all): iOS and Android
  3. Add the appropriate “Tag” based on what Expo library you have a question on.
    expo-av

I can successfully record files in wav, ma4 and caf format but when I try to play them back, I get an error that says format not supported. Here is my code to play back the audio files.

useEffect(() => {
const playAudio = async () => {
const signedUrl = await getAudioSignedUrl(moodId,uri,‘audio’)
console.log(AUDIO URL: ${signedUrl})
await Audio.requestPermissionsAsync();
await Audio.setAudioModeAsync({
staysActiveInBackground: false,
shouldDuckAndroid: false,
playThroughEarpieceAndroid: false,
allowsRecordingIOS: false,
playsInSilentModeIOS: true,
});
const { sound } = await Audio.Sound.createAsync({ uri: signedUrl },{shouldPlay: true});

  sound.setOnPlaybackStatusUpdate((status) => {
    if (status.didJustFinish) {
      sound.unloadAsync();
    }
  });

  await sound.playAsync();

  return () => {
    sound.unloadAsync();
  };
};

playAudio();

}, );

I have searched StackOverflow but those suggestions did not help. Any ideas?

Had similar issues. My walk-arounds:
Play as video using import { Video } from ‘expo-av’; and I used the code from here https://docs.expo.dev/versions/latest/sdk/video/#usage. and only used the Button component. It saved me a lot of stress.

   <Button
          title={status.isPlaying ? 'Pause' : 'Play'}
          onPress={() =>
            status.isPlaying ? video.current.pauseAsync() : video.current.playAsync()
          }
        />

Second method was to play the audio in browser:

import * as Linking from 'expo-linking';
await Linking.openURL('link to your audio file');

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.