所以我试图在骨干代码中实现youtube API。youtube iframe api不能在支持firefox的骨干上工作
我把API在视图中,并尝试从那里运行一切
它在Chrome,但isen't在Firefox中,我们假设触发如果YouTube API加载完成ISEN”事件运行的伟大工程没有开火。如果甚至试图将警报放在那里以查看它是否与上下文相关,则此警报将在Chrome中运行,但不在Firefox中运行。
之前有人看过类似的东西吗?
我使用骨干0.9和YouTube的iframe API
活生生的例子:http://alpha.mychannls.com/channel/8
相关代码
App.Views.youtubePlayer = Backbone.View.extend({
defaults: {
'wmode': 'transparent',
'height': '420',
'width': '740',
'volume': '40',
'playerVars': {
'wmode': 'transparent',
'origin': 'http://www.youtube.com',
'enablejsapi': 1,
'autoplay': 0,
'controls': 1,
'iv_load_policy': 3,
'showinfo': 0,
'rel': 0,
'allowfullscreen': 1,
'allowtransparency': 'yes'
}
},
initialize: function(options) {
//bind youtubeplay event to play method
this.collection.bind('youtubePlay', this.play, this);
//bind youtubestop to stop method
this.collection.bind('youtubeStop', this.stop, this);
//extend this.o so the options are globally accessable
this.o = $.extend(true, this.defaults, options);
this.render();
},
render: function() {
//create a new youtube player
var view = this;
console.log("this is run by firefox");
this.ytplayer = new window.YT.Player('ytplayer', {
'events': {
'onReady': view.onPlayerReady,
'onError': view.onError,
'onStateChange': view.onPlayerStateChange
}
});
return this;
},
//when youtube player is ready to run
onPlayerReady: function(e){
console.log('this function isent run in firefox');
//start the first video
App.videos.youtubeready();
}
});
主干代码之外,因为YouTube API播放器需要被宣布全球
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
function onYouTubeIframeAPIReady() {
App.youtubeplayer = new App.Views.youtubePlayer({ el: '#ytplayer' , collection : App.videos } );
}
整个代码在这里可以
http://alpha.mychannls.com/js/channel.js
这将有助于查看整个页面的实时演示,而不仅仅是独立的JavaScript。这样我们就可以使用Firefox的JavaScript调试器来浏览代码,看看发生了什么。 – 2013-03-27 20:27:35
杰夫:我看到一个非常类似的问题,与FF + Backbone.js和YT IFrame API有关。每次用户点击导航应用程序(pushState)时,YT IFrame都会重新触发onReady事件。 Firefox可能会触发YT Iframe重新加载onPopState(),但很难说 - 这种行为至少表明了这一点。 我会尝试为此创建一个更好的简化测试用例。 – tvpmb 2013-04-09 22:31:26