2

我有几个Media文件要播放。但它们必须一一播放。像:

var play_media;
play_media= new Media("../record/01.mp3",Success,Error);
play_media.play();
//And as the `../record/01.mp3` media file is done. 
//I will release it and create another one to play. 
play_media= new Media("../record/02.mp3",Success,Error);

但似乎一个媒体的播放完成后,它什么也没有返回。
我能怎么做 ?

4

3 回答 3

1

尝试这样的事情:

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;
    }
}
于 2013-01-14T13:06:27.390 回答
0

首先用 media.getDuration: 找到音频片段长度,然后使用 setTimeout 函数播放下一首歌曲。这样你就可以连续播放多首歌曲

于 2013-01-13T06:40:03.890 回答
0

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

           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);
于 2014-08-22T13:20:39.123 回答