Javascript 如何使用PhoneGap连续播放音频?

Javascript 如何使用PhoneGap连续播放音频?,javascript,html,cordova,phonegap-plugins,Javascript,Html,Cordova,Phonegap Plugins,我有几个媒体文件要播放。但他们必须一个接一个地玩。 比如: 但似乎当一个媒体的剧本完成时,它什么也没有回报。 如何操作?首先使用media.getDuration查找音频剪辑长度: 并使用设置超时功能播放下一首歌曲。 通过这种方式,您可以连续播放多首歌曲尝试以下方法: var media = {"../record/01.mp3","../record/02.mp3","../record/03.mp3"}; var next = 0, play_media; for(int i=0; i<

我有几个
媒体
文件要播放。但他们必须一个接一个地玩。 比如:

但似乎当一个媒体的剧本完成时,它什么也没有回报。

如何操作?

首先使用media.getDuration查找音频剪辑长度: 并使用设置超时功能播放下一首歌曲。
通过这种方式,您可以连续播放多首歌曲

尝试以下方法:

var media = {"../record/01.mp3","../record/02.mp3","../record/03.mp3"};
var next = 0, play_media;
for(int i=0; i<media.lenght; i++){
    play_media= new Media(media[next]);
    play_media.play();
    if(soundTimer == null){
        soundTimer = setInterval(function(){
            vpSound.getCurrentPosition(
                function(position){
                    if(position > -1){
                        //Do something if you want 
                    }
                }
            );
        }, 1000);
        next = next + 1;
    }
}
var媒体={./record/01.mp3“,”./record/02.mp3“,”./record/03.mp3“};
var next=0,播放媒体;
对于(int i=0;i-1){
//如果你想做什么就做什么
}
}
);
}, 1000);
下一个=下一个+1;
}
}

将Media.getCurrentPosition()与javascript setInterval一起使用,并将其设置为每秒间隔(1000),以获取正在播放的曲目的位置。然后检查曲目的位置是否等于-0.001,这意味着它已结束。从那里你可以转到下一首曲目,或者如果这是最后一首曲目,请使用Media.release()

mediaSuccess:(可选)在媒体对象完成当前播放/录制或停止操作后调用的回调。这可能会触发播放下一首歌你是说媒体(,,,,“mediaSuccess”)?我会研究的。谢谢
var media = {"../record/01.mp3","../record/02.mp3","../record/03.mp3"};
var next = 0, play_media;
for(int i=0; i<media.lenght; i++){
    play_media= new Media(media[next]);
    play_media.play();
    if(soundTimer == null){
        soundTimer = setInterval(function(){
            vpSound.getCurrentPosition(
                function(position){
                    if(position > -1){
                        //Do something if you want 
                    }
                }
            );
        }, 1000);
        next = next + 1;
    }
}
           var mediaTimer = setInterval(function () {
               media.getCurrentPosition(function (position) {
                     if (position > -0.001) {
                        //Do something like update a progress bar and set times.
                     }
                     else if (position === -0.001) {
                           selectedIndex = selectedIndex + 1; //selectedIndex is the index of the song chosen in a list.
                          if (selectedIndex > playlistLength) {
                              media.release();
                          } 
                          else {
                            var nextTrack = app.FolderList.tracks[selectedIndex]; //get the next track from a list of tracks using the selectedIndex
                            playPause(nextTrack.SongPath);//playPause() is used to initialize a new Media object with the new track and then plays it.
                          }
                     },
                     function () {
                     console.log('Unable to retrieve media position: ' + error.code);
                       });
                    },
                    1000);