Expo Audio只播放一首歌曲,只播放一次

时间:2018-12-11 09:16:14

标签: javascript reactjs react-native audio expo

我们正在使用Expo Player构建应用程序。 它具有暂停按钮并可以播放。 我的播放器现在有两个问题:

  1. 它只播放一次通过道具发送的声音文件!
  2. 它会忽略我之后(当它完成时)或它工作时发送的其他声音文件。
    -它应该停止并播放新的,或者如果相同的文件-(path),则从头开始。
    我尝试解决AV - Expo Documantation(initialStatuse等)的问题,但没有给出那里的代码。

我的播放器代码:

const playerObject = new Expo.Audio.Sound();
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>

很高兴能帮助我们。

0 个答案:

没有答案