在弹出的YouTube视频犯规停止播放时窗口关闭 [英] Youtube video in popup doesnt stop playing when window closed

查看:428
本文介绍了在弹出的YouTube视频犯规停止播放时窗口关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上,我有一个弹出code,使一个DIV弹出。这里面,有一个YouTube视频播放器。一切正常,直到我关闭窗口,我仍然可以听到背景意味着该视频仍在播放音乐。我想停止它。
我做了一些研究,倒在YouTube的API,但它仍然不起作用。

So basically, I have a pop up code that makes a div pop up. Inside that, there is a youtube video player. Everything works, until I close the window, I can still hear the music in background meaning that the video is still playing. I want to stop it. I did some research and fell on the youtube API's, but it still doesnt work.

下面是我的code为分区

Here is my code for the div

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>";

这里是code为弹出:

And here is the code for the pop up:

//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();
}
}

感谢您,
ARA

Thank you, Ara

推荐答案

我一直在寻找在的Youtube文档( IFRAME),我认为你是混合了不同的API

I was looking over the Youtube Documentation(iframe) and I think you are mixing up the different api's

的JavaScript API 它规定

我们建议使用SWFObject嵌入,将使用JavaScript API访问的任何球员。

We recommend using SWFObject to embed any players that will be accessed using the JavaScript API.

但是,你正在使用的iframe。所以,我认为你需要创建一个名为函数

But you are using an iframe. So I think you need to create a function called

函数onYouTubeIframeAPIReady()

其中有几行code的设置都与其他功能一起​​。

Which has several lines of code to setup everything along with other functions.

这篇关于在弹出的YouTube视频犯规停止播放时窗口关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆