我如何循环播放列表中的所有音频并做出反应

时间:2018-08-12 09:06:01

标签: javascript react-native react-native-sound

我正在尝试使用react native和react-native-sound制作音频播放器。

我想循环播放列表中的所有音频,一次播放一次。我该怎么办?

这是我的代码:

const songs = [
    {
        title: 'one',
        url: 'one.mp3'
    },
    {
        title: 'two',
        url: 'two.mp3'
    },
    {
        title: 'three',
        url: 'three.mp3'
    },
    {
        title: 'four',
        url: 'four.mp3'
    },
];

function playSound(song) {
    song = new Sound(song.url, Sound.MAIN_BUNDLE, (error) => {
        if (error){
          //
        } else {
            song.play((success) => {
                song.release();
           });
        }
    });
}

function playAll() {
    Object.keys(songs).forEach(function(key) {
        playSound(songs[key])
    });
}

我尝试使用setTimeOut()进行循环,但不知道如何将超时时间设置为与音频时间完全相同。

0 个答案:

没有答案