我正在尝试使用SoundManager2和Soundcloud提供的选项构建我自己的soundcloud媒体播放器.
这是我目前的代码:
SC.stream('/tracks/' + this.media.mediaId,function(audio){
audio.load({
onload : function(){
var duration = this.duration;
},onfinish : function(){
self.updatePlayButton();
console.log('Finished');
},onresume : function(){
self.updatePlayButton();
console.log("resumed");
},onstop : function(){
self.updatePlayButton();
console.log("Stopped");
},onpause : function() {
self.updatePlayButton();
console.log('Paused');
},whileplaying : function()
{
console.log(this.position);
self.updateScrubber(this.position / (this.duration / 100));
self.$timeLeft.text(self.formatTime(this.position / 1000));
console.log(totalPercent,'My position');
}
});
self.audio = audio.sID;
self.registerEvents();
});
我使用以下方式播放音频:
soundManager.getSoundById(self.audio).togglePause();
音频播放和所有回调都相应地触发.但是在“onfinish”回调之后,当我再次点击播放时它将重放音频,但它不会触发任何事件.
我做错了什么?
最佳答案
根据
SC.stream()
的文档,“options”对象可以作为第二个参数传入:
SC.stream(trackPath,[options],[callback])
选项将与soundobject本身相关联,因此在调用.load()和.play()等单个方法时,您无需再次声明它们.
尝试拨打这样的电话:
var myOptions = {
onload : function() {
var duration = this.duration;
},onfinish : function(){
self.updatePlayButton();
console.log('Finished');
},onresume : function(){
self.updatePlayButton();
console.log("resumed");
},onstop : function(){
self.updatePlayButton();
console.log("Stopped");
},onpause : function() {
self.updatePlayButton();
console.log('Paused');
},whileplaying : function() {
console.log(this.position);
self.updateScrubber(this.position / (this.duration / 100));
self.$timeLeft.text(self.formatTime(this.position / 1000));
console.log(totalPercent,'My position');
}
}
SC.stream('/tracks/' + this.media.mediaId,myOptions,function(audio){
audio.load();
self.audio = audio.sID;
self.registerEvents();
});
您的代码还有一些其他奇怪的东西,例如在onload函数中没有对变量持续时间做任何事情.此外,使用变量self同时也使用此结果看起来你不确定你是在编写Python还是JavaScript,但也许它对你有意义.
原文地址:https://www.jb51.cc/js/429802.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。