如何在Youtube中使用Javascript停止视频? [英] How can I stop a video with Javascript in Youtube?

查看:150
本文介绍了如何在Youtube中使用Javascript停止视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况:
此处在哪里我按了一些视频。

Situation: here, where I pressed some video.

问题:我尝试在Firebug的控制台中通过Javascript停止视频:

Problem: I try to stop the video by Javascript in the console of Firebug:

player.stopVideo(playerid):Void   [1] [2]

问题:为什么上面的命令不起作用?

Question: Why does not the command above work?

[1] 来源部分player.stopVideo():Void

[1] Source for the part "player.stopVideo():Void"

[2]我从源头看到了带有Firebug的播放器。

[2] I looked playerid with Firebug from the source.

推荐答案

您的视频正在请求启用JSAPI,所以你非常接近!您所需要的只是嵌入式播放器的有效参考。检查您的页面显示您使用HTML DOM元素IDplayerid来识别您的播放器。

Your video is requesting w/ the JSAPI enabled, so you are very close! All you need is a valid reference to the embedded player. Inspecting your page revealed that you are using the HTML DOM element id of "playerid" to identify your player.

示例:

<embed id="playerid" width="100%" height="100%" allowfullscreen="true" allowscriptaccess="always" quality="high" bgcolor="#000000" name="playerid" style="" src="http://www.youtube.com/apiplayerbeta?enablejsapi=1&playerapiid=normalplayer" type="application/x-shockwave-flash">

要获得对播放器的引用,然后停止视频,请使用以下代码:

To obtain a reference to the player and then stop the video use the following code:

var myPlayer = document.getElementById('playerid');
myPlayer.stopVideo();

这篇关于如何在Youtube中使用Javascript停止视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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