だから私はバックボーン コードで youtube API を実装しようとしています。
ビューに API を配置し、そこからすべてを実行しようとします
Chrome では問題なく動作しますが、Firefox では実行されていません。YouTube API の読み込みが完了したときにトリガーされるはずのイベントが発生しません。そこにアラートを入れて、コンテキストに関連しているかどうかを確認しようとしても、このアラートはクロムでは実行されますが、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 } );
}
コード全体はここにあります