0

反应原生声音 - 第一次播放音频没问题,当我尝试在下一个音频文件之后播放它时,它总是在播放第二个音频文件。

我的目标是我想从数组中播放第 n 个音频,每当我尝试播放下一个音频时,我想从 new Sound() 函数中删除第一个音频

“反应原生”:“0.66.4”,“反应原生声音”:“^0.11.1”,

//this is play function
const playSound = ({item, index}) => {

    for (var i = 0; i < items.length; i++) {

      if (item.id === items[i].id) {
    enter code here
        sound = new Sound(item.uri, error => {
          if (error) {
            console.log('failed to load the sound', error);
            return;
          }
          // loaded successfully

          sound.play(success => {
            if (success) {
              console.log('successfully finished playing');
              // Release when it's done so we're not using up resources
              sound.release();
            } else {
              console.log('playback failed due to audio decoding errors');
            }
          });
        });
      } else {
        // sound.reset();
        sound.reset();
        // sound.stop();
      }
    }
  };

//this is my main function

return (
    <View style={styles.container}>
      {/* Header Area */}
     <Header title="স্বরধ্বনি&quot; navigation={navigation} active={1} />
      {/* Header Area */}
      <FlatGrid
        itemDimension={90}
        data={items}
        style={styles.gridView}
        // staticDimension={300}
        // fixed
        spacing={5}
        renderItem={({item, index, data}) => {
          return (
            <TouchableOpacity
              style={styles.itemContainer}
              activeOpacity={0.3}
              onPress={() => playSound({item, index})}>
              <Text style={styles.itemName}>{item.title}</Text>
            </TouchableOpacity>
          );
        }}
      />
    </View>
  );
4

0 回答 0