javascript - 钛音乐播放器进度事件监听器状态未触发
<p><p>我的音乐播放器没有更新进度。</p>
<p>暂停和播放音乐没有问题,例如:</p>
<pre><code>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();
}
});
</code></pre>
<p>但是当我添加事件监听器时,它永远不会触发:</p>
<pre><code>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.id + ".mp3"});
music.play();
music.complete = function(){
playlist.splice(0,1)
if (playlist.length!=0){
music = Ti.Media.createSound({url:"../sounds/" + playlist.id + ".mp3"});
music.play();
}
};
music.addEventListener('progress',function(e) {
Ti.API.info('Time Played: ' + Math.round(e.progress) + ' milliseconds');
});
}
</code></pre>
<p>有什么想法吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您正在向 <a href="http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Media.Sound" rel="noreferrer noopener nofollow">Ti.Media.Sound</a> 添加事件监听器寻找 <code>progress</code> 事件的对象。此对象仅发出 <code>change</code>、<code>complete</code>、<code>error</code>、<code>interrupted</code>、<code>resume</code> 事件.您要查找的对象是 <a href="http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Media.AudioPlayer-event-progress" rel="noreferrer noopener nofollow">Ti.Media.AudioPlayer</a> .</p>
<p>此外,使用 AudioPlayer,您无需重新创建整个对象即可跳到下一首轨道。只需使用 <code>setUrl()</code> 方法:</p>
<pre><code>music.setUrl("../sounds/" + playlist.id + ".mp3");
</code></pre></p>
<p style="font-size: 20px;">关于javascript - 钛音乐播放器进度事件监听器状态未触发,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/20829207/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/20829207/
</a>
</p>
页:
[1]