YouTube的I幀API的流程如下:
- 負載的YouTube API。
- 加載時,將調用全局方法
onYouTubeIframeAPIReady
。
- 在這種方法中,會創建一個包裝來與帶框的YouTube播放器進行交互。
的onPlayerReady
方法,你的問題是步驟3中的一部分,我繼續發言之前,我展示的the example從官方文檔的一部分。
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
// ...
events: {
'onReady': onPlayerReady // <-------
// ...
在這個例子中,你清楚地看到,你是在onPlayerReady
功能結合到一個特定的事件。對於兩名球員採取不同的行動,你可以簡單地使用不同的功能。
player1 = new YT.Player('id_of_player1', {
events: {
'onReady': onPlayerReady1
} // ...
};
player2 = new YT.Player('id_of_player2', {
events: {
'onReady': onPlayerReady2
} // ...
};
這是我預期的更容易!謝謝! – Chris