2013-07-02 4 views
0

나는 5 개 이상의 youtube 비디오 플레이어를 가지고 있지만 두 번째를 만든 후에 몇 가지 문제가 있습니다. 두 번째를 만들면 처음은 사라지고 무엇이 잘못되었는지 알 수 없습니다.여러 개의 유튜브 API 플레이어가 있습니까?

도움을 주시면 감사하겠습니다. 감사합니다.

//slide 2 

var tag = document.createElement('script'); 


    tag.src = "https://www.youtube.com/iframe_api"; 
    var firstScriptTag = document.getElementsByTagName('script')[0]; 
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 

    // 3. This function creates an <iframe> (and YouTube player) 
    // after the API code downloads. 



    var player; 
    function onYouTubeIframeAPIReady() { 
    player = new YT.Player('player', { 
    height: '820', 
    width: '707', 
    videoId: 'NTq1WLKuOI4', 
    events: { 
    'onReady': onPlayerReady, 
    'onStateChange': onPlayerStateChange 
     } 
    }); 
    }  

    function onPlayerReady(event) { 
    setTimeout(function(){player.playVideo(); },8000); 
    } 

    // 5. The API calls this function when the player's state changes. 
    // The function indicates that when playing a video (state=1), 
    // the player should play for six seconds and then stop. 
    var done = false; 
    function onPlayerStateChange(event) { 
    if (event.data == YT.PlayerState.PLAYING && !done) { 
    setTimeout(stopVideo, 29000); 
    done = true; 
    } 
    } 

    function stopVideo() { 
    player.stopVideo(); 
    slide2(); 
    move(); 
    } 


var slide2 = function(){   
    setTimeout(function(){  
    slide3(); 
    move(); 
    },9000); 

} 


    //slide3 

    var player; 
    function onYouTubeIframeAPIReady() { 
    player2 = new YT.Player('player2', { 
    height: '820', 
    width: '707', 
    videoId: 'AQx1UjLv3Ps', 
    events: { 
    'onReady': onPlayerReady, 
    'onStateChange': onPlayerStateChange 
     } 
    }); 
    }  

    function onPlayerReady(event) { 
    setTimeout(function(){player2.playVideo(); },8000); 
    } 

    // 5. The API calls this function when the player's state changes. 
    var done = false; 
    function onPlayerStateChange(event) { 
    if (event.data == YT.PlayerState.PLAYING && !done) { 
    setTimeout(stopVideo2, 29000); 
    done = true; 
    } 
    } 

    function stopVideo2() { 
    player2.stopVideo(); 

    } 
+0

나는 이것을 이해할 수 없다. 누군가? –

+0

그걸 알아 냈어 - [솔루션] (http://stackoverflow.com/questions/17012886/loading-multiple-video-players-with-youtube-api) –

+0

가능한 복제본 [두 번째 비디오는 반복 호출 후 계속 반복됩니다. 첫 번째 끝 - youtube API?] (http://stackoverflow.com/questions/17441532/second-video-keeps-looping-after-is-being-called-on-the-firsts-end-youtube-ap) –

답변

1

두 번 이상 onYouTubeIframeAPIReady()를 호출 할 수 없습니다. 귀하는 모든 YouTube 플레이어 프레임을 실시간으로 초기화해야합니다. onYouTubeIframeAPIReady의 내용을 새로운 명명 된 함수로 래핑 한 다음 onYouTubeIframeAPIReady 내에서 모두 호출하십시오.