我正在使用Soundmanager2播放器在Ember中构建音频播放器/播放列表。
我将以下代码用于播放/暂停操作,这些操作会触发歌曲的播放和暂停。
我遇到的问题是歌曲会播放,但暂停不起作用。我认为这是因为暂停动作中的变量mySound从技术上来说是与播放动作中的mySound不同的歌曲。
这是我的代码:
actions: {
play: function(){
var track_id = this.id;
var mySound = soundManager.createSound({
id: track_id,
url: 'https://api.soundcloud.com/tracks/' + track_id + '/stream?client_id=d61f17a08f86bfb1dea28539908bc9bf',
autoplay: false,
whileplaying: function() {
$('#positionBar').css('width', ((this.position/this.duration) * 100) + '%');
},
});
this.set("isPlaying", true);
soundManager.stopAll();
mySound.play();
},
pause: function(){
var track_id = this.id;
var mySound = soundManager.createSound({
id: track_id,
url: 'https://api.soundcloud.com/tracks/' + track_id + '/stream?client_id=d61f17a08f86bfb1dea28539908bc9bf',
autoplay: false,
whileplaying: function() {
$('#positionBar').css('width', ((this.position/this.duration) * 100) + '%');
},
});
this.set("isPlaying", false);
mySound.pause();
},
}
任何帮助都会有所帮助。我是Ember的新手,所以也许我可以采用其他更有效的方法来完成此操作。
只需跟踪该mySound
属性,然后在pause方法中使用它即可。
actions: {
play: function(){
var track_id = this.id;
var mySound = soundManager.createSound({
id: track_id,
url: 'https://api.soundcloud.com/tracks/' + track_id + '/stream?client_id=d61f17a08f86bfb1dea28539908bc9bf',
autoplay: false,
whileplaying: function() {
$('#positionBar').css('width', ((this.position/this.duration) * 100) + '%');
},
});
this.set("isPlaying", true);
this.set('mySound', mySound);
soundManager.stopAll();
mySound.play();
},
pause: function(){
var mySound = this.get('mySound');
this.set("isPlaying", false);
if(mySound && mySound.pause){
mySound.pause();
}
},
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句