我的Backbone应用程序中有一个事件处理程序,用于侦听YouTube视频何时结束,然后查找下一个视频并播放它。它在桌面上完美运行,但不适用于iOS。它识别事件并触发处理程序,但是由于某种原因,我的if语句不起作用。为什么这个if语句在我的事件处理程序中不能在iOS上工作?
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。因此,您可以添加try catch块并在catch中调用alert以检测是否存在某些js错误。 – aleha 2014-09-18 20:25:46