jquery
  • api
  • youtube
  • 2012-08-15 2 views 1 likes 
    1

    그래서 기본적으로 나는 팝업 팝업을 팝업 팝업으로 가지고있다. 그 안에는 YouTube 비디오 플레이어가 있습니다. 모든 것은 작동합니다. 창을 닫을 때까지 배경 음악이 들리면 여전히 비디오가 재생 중입니다. 나는 그것을 멈추고 싶다. 나는 약간의 연구를했고 유튜브 API에 떨어졌지만, 여전히 작동하지 않습니다.팝업창의 유튜브 비디오가 창을 닫을 때 멈추지 않는다

    여기 사업부

    echo "<div id='popupContact'>"; 
    echo "<a id='popupContactClose'>x</a>"; 
    echo "<div><h1>" .$row['title']. "</h1></div>"; 
    echo "<p id='contactArea'>"; 
    if($row[type] == "image") 
    echo "<img src='gallery/" .$row['path']. "' alt='" .$row['title']. "'/>"; 
    else 
    echo "<iframe width='560' height='315' src='http://www.youtube.com/v/" .$row['path']."?  enablejsapi=1&version=3&playerapiid=ytplayer' frameborder='0' allowfullscreen></iframe>"; 
    echo "<br/><br/>" .$row['description']. "</p>"; 
    echo "</div>"; 
    echo "<div id='backgroundPopup'></div>"; 
    

    내 코드입니다 그리고 여기 팝업에 대한 코드입니다 :

    //CONTROLLING EVENTS IN jQuery 
    $(document).ready(function(){ 
    
    //LOADING POPUP 
    //Click the button event! 
    $("#button").click(function(){ 
        //centering with css 
        centerPopup(); 
        //load popup 
        loadPopup(); 
    }); 
    
    //CLOSING POPUP 
    //Click the x event! 
    $("#popupContactClose").click(function(){ 
        disablePopup(); 
    }); 
    //Click out event! 
    $("#backgroundPopup").click(function(){ 
        disablePopup(); 
    }); 
    //Press Escape event! 
    $(document).keypress(function(e){ 
        if(e.keyCode==27 && popupStatus==1){ 
         disablePopup(); 
        } 
    }); 
    
    }); 
    
    //disabling popup with jQuery magic! 
    function disablePopup(){ 
    //disables popup only if it is enabled 
    if(popupStatus==1){ 
        $("#backgroundPopup").fadeOut("slow"); 
    $("#popupContact").fadeOut("slow"); 
    popupStatus = 0; 
    stop(); 
    } 
    } 
    function onYouTubePlayerReady(playerId) { 
    alert("YAY"); 
    ytplayer = document.getElementById("ytplayer"); 
    } 
    
    function stop() { 
    if (ytplayer) { 
    ytplayer.stopVideo(); 
    } 
    } 
    

    감사합니다, 아라

    +0

    나는() { \t //로드는 팝업 있습니다 .. #button 클릭 할 때 호출되는') (기능'loadPopup에 대한 – jmm

    +0

    기능 loadPopup를 코드를 볼 수 없습니다 \t 경우 (. popupStatus == 0) { \t \t $ ("#의 backgroundPopup") CSS ({ \t \t \t "불투명" "0.7" \t \t}); \t \t $ ("# backgroundPopup") .fadeIn ("slow"); \t \t $ ("# popupContact") .fadeIn ("slow"); \t \t popupStatus = 1; \t} } – user1049769

    +0

    내 답변에 나열된 설명서를 검토 했습니까? – jmm

    답변

    0

    나는 당신이 혼합 생각이

    을 내용의 JavaScript API

    다른 API의

    JavaScript API를 사용하여 액세스 할 플레이어를 퍼가려면 SWFObject를 사용하는 것이 좋습니다.

    하지만 iframe을 사용하고 있습니다. 그래서 당신이 함수를 만들 필요가 있다고 생각은 다른 기능과 함께 설치 모두에 여러 줄의 코드를 가지고

    function onYouTubeIframeAPIReady()

    을했다. 가 무효 인 경우

    0

    변수 범위. onYouTubePlayerReady() 함수 안에 ytplayer을 정의한 경우에만 값을 반환하지 않습니다. 해당 함수가 반환되면 ytplayer 값이 소멸됩니다.

    당신은 함수의 변수 바깥 정의해야합니다 : 나는 Youtube Documentation(iframe) 찾고 있었다

    var ytplayer; // now a global variable. 
    function onYouTubePlayerReadye(playerID) { 
        ytplayer = document.getElementById('ytplayer'); 
    } 
    
    +0

    그래도 작동하지 않습니다 .... onYouTubePlayerReady (playerId)가 호출되지 않는다고 생각합니다. 함수에 테스트 경고를 배치했는데 결코 호출되지 않습니다. – user1049769

    관련 문제