Expo Audio plays only one song and one time only!


#1

we are trying to build an app with a player that will work perfectly.
it has a pause button and play.
I have now two problem with my player:

  1. It plays the sound file I send through the props only one time!
  2. it ignors other sound files I send it.
    I tried to solve it with the AV - Expo Documantation (initialStatuse, ect…) but didnt succeed with the codes gives there.

My code:

const playing = false;

render() {
  return (
    <View>
      <Card wrapperStyle={{ width: 346, height: 180 }}>
        <View style={{ flexDirection: "row" }}>
          <Text style={styles.resultsContainer}>
            {this.state.song.Song_Name}{" "}
          </Text>
          <Image
            style={styles.imageContainer}
            source={{ uri: this.state.song.Image }}
          />
        </View>
        <View style={styles.buttonRow}>
          <Ionicons
            name="md-play"
            size={40}
            color="black"
            onPress={async () => {
              try {
                if (!playing) {
                  await playerObject.loadAsync({
                    uri: this.state.song.Song_File 
                  });
             
                }
                await playerObject.playAsync();
              } catch (error) {}
            }}
          />
          <View style={{ flex: 0.1 }}> </View>
          <Ionicons
            name="md-pause"
            size={40}
            color="black"
            onPress={async () => {
              playing = true;
              try {
                {
                  await playerObject.pauseAsync();
                }
              } catch (error) {}
            }}
          />

          {/* )} */}
        </View>
      </Card>

Glad if you can help,


Audio trying to update unmounted Component on Android
#2

Use setTimeout out for updating state


#3

It won’t work. each song has it one time,
And I if press the play button again (not after pausing it ) I want it to start all over again.


#4

I’ve heard Expo Audio doesn’t work in the background, I use a WebView to play audios instead it.

<audio id="player"></audio>
// Add some listeners, use postMessage() to send to the app
function onLoad() {
  _player = document.getElementById('player');
  _player.addEventListener('timeupdate', _handleOnTimeUpdate);
  _player.addEventListener('canplaythrough', _handleOnCanPlayThrough);
  _player.addEventListener('ended', _handleOnEnded);
  _player.addEventListener('error', _handleOnError);
}

// Play a file
_player.src = 'blah blah blah';
_player.play();

@expertlate Does Expo Audio works in the background?


#5

No it doesn’t work in the background but yes in silence mode, and I don’t know how to work with WebView to play audio files.


closed #6

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