Titanium音乐播放器进度事件监听器状态未触发

时间:2013-12-29 19:27:50

标签: javascript ios audio titanium titanium-mobile

我有一个没有更新进度的音乐播放器。

例如,暂停和播放音乐没有问题:

if (music.isPlaying()) {
    var btnsrc = '../images/btn_pause.png'
} else {
    var brnsrc = '../images/btn_play.png';
}

var playButton = Ti.UI.createButton({
    title: '',
    backgroundImage: '../images/btn_pause.png',
    width:34,
    height:34,
    top:10,
    left:10
});

playButton.addEventListener('click',function(e){
    if (!music.isPaused()) {
        music.pause();
    } else {
        music.play();
    } 
});

但是当我添加事件监听器时,它永远不会触发:

if (!music.isPlaying()) {   
    Ti.API.info('novid=' + robj.curel);     
    var nove = {index: robj.curel+2, rowData: {}};
    nove.rowData.tourid = robj.tour;
    dispLocDetails(nove);
    music = Ti.Media.createSound({url:"../sounds/" + playlist[0].id + ".mp3"});     
    music.play();   
    music.complete = function(){        
        playlist.splice(0,1)        
        if (playlist.length!=0){
            music = Ti.Media.createSound({url:"../sounds/" + playlist[0].id + ".mp3"});                 
            music.play();                                                   
        }   
    };

    music.addEventListener('progress',function(e) {
        Ti.API.info('Time Played: ' + Math.round(e.progress) + ' milliseconds');    
    }); 
}

任何想法为什么?

1 个答案:

答案 0 :(得分:1)

您正在向Ti.Media.Sound对象添加事件侦听器,以查找progress事件。此对象仅发出changecompleteerrorinterruptedresume个事件。您要查找的对象是Ti.Media.AudioPlayer

使用AudioPlayer,您无需重新创建整个对象即可跳至下一首曲目。只需使用setUrl()方法:

music.setUrl("../sounds/" + playlist[0].id + ".mp3");