【发布时间】:2014-09-18 20:14:14
【问题描述】:
我的 Backbone 应用程序中有一个事件处理程序,用于侦听 YouTube 视频何时结束,然后找到下一个视频并播放它。它可以在桌面上完美运行,但不能在 iOS 上运行。它识别事件并触发处理程序,但我的 if 语句由于某种原因不起作用。
App.Player.addEventListener('onStateChange', function(newState){
// Play / Pause functionality
var currentSong = App.Player.getVideoData();
if (theVideoId == currentSong.video_id){
if (newState.data == 1){
$("#play-pause").addClass("playing")
} else if (newState.data == 2){
$("#play-pause").removeClass("playing")
}
};
// When song ends, play the next song in playlist
if (newState.data == 0){
for (var i=0; i < App.playList.size(); i++){
if (App.playList.models[i].get("id") == App.nowPlaying.get("id")){
// none of this code executes on iOS, but works fine on desktop
var nextVideo = App.playList.models[i+1];
var promise = nextVideo.fetch();
$.when(promise).then(function(){
App.Player.cueVideoById(nextVideo.get("video")).playVideo();;
App.nowPlaying = nextVideo;
});
}
}
}
});
},
知道为什么会发生这种情况,我该如何解决?
【问题讨论】:
-
哪个'if'不起作用?很难在 iOS 设备上检查 javascript。所以你可以在catch中添加try catch块并调用alert来检测是否有一些js错误。
标签: javascript ios backbone.js marionette youtube-javascript-api