我正在建立一個音樂網站,其中有多首歌曲,每個都有自己的播放/暫停按鈕,然後是一個具有主播放/暫停按鈕的全局播放器。我無法弄清楚如何觸發計算出的屬性,這樣當我單擊單個歌曲上的播放按鈕時,主播放/暫停按鈕也會從播放切換爲暫停,反之亦然。Ember.js - 在控制器外部觸發屬性
我有以下代碼
Tracks.TrackController = Ember.ObjectController.extend({
currentTime: 0,
isLoaded: false,
isPlaying:false,
songStarted:false,
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) + '%');
},
});
songStarted:true;
this.set("isPlaying", true);
this.set('mySound', mySound);
soundManager.stopAll();
mySound.play();
},
pause: function(){
var mySound = this.get('mySound');
this.set("isPlaying", false);
this.set("isPaused", true);
if(mySound && mySound.pause){
mySound.pause();
}
},
resume: function(){
var mySound = this.get('mySound');
this.set("isPlaying", true);
this.set("isPaused", false);
mySound.resume();
}
}
});
,並以此爲標記:
{{#if isPlaying}}
<li class="playBtn pause"><button {{action 'pause' this}} class="play-btn sm2_button" id="masterPlayBtn"></button></li>
{{else}}
{{#if isPaused}}
<li class="playBtn"><button {{action 'resume' this}} class="play-btn sm2_button" id="masterPlayBtn"></button></li>
{{else}}
<li class="playBtn"><button {{action 'play' this}} class="play-btn sm2_button" id="masterPlayBtn"></button></li>
{{/if}}
{{/if}}
我想我需要將動作添加到
Tracks.TracksController = Ember.ArrayController.extend({
});
控制器,但那是我迷路了。我似乎無法弄清楚如何將isPlaying設置爲主播放/暫停按鈕,並調用操作,以便當我點擊主暫停/播放按鈕時,它會找到一首特定的歌曲並播放。