状況: ここで、私はいくつかのビデオを押しました。
問題: Firebug のコンソールで Javascript によってビデオを停止しようとしています:
player.stopVideo(playerid):Void [1] [2]
質問:上記のコマンドが機能しないのはなぜですか?
[1] 「player.stopVideo():Void」部分のソース
[2] ソースから Firebug で playerid を調べました。
あなたのビデオは JSAPI を有効にした状態でリクエストしているので、非常に近いです! 必要なのは、埋め込みプレーヤーへの有効な参照だけです。ページを調べたところ、「playerid」の HTML DOM 要素 ID を使用してプレーヤーを識別していることがわかりました。
例:
<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">
プレーヤーへの参照を取得してビデオを停止するには、次のコードを使用します。
var myPlayer = document.getElementById('playerid');
myPlayer.stopVideo();
以下はうまく機能し、wamp サーバーでテストされています。次の行の 11 桁の ID を、再生したいビデオの ID に置き換えるだけです。
http://www.youtube.com/v/***LpbzbyGjJGE***?enablejsapi=1&version=3&playerapiid=ytplayer
幸運を。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<a href="#" onclick="var myPlayer = document.getElementById('playerid'); myPlayer.pauseVideo();">Pause</a>
<a href="#" onclick="var myPlayer = document.getElementById('playerid'); myPlayer.playVideo();">Play</a>
<embed id="playerid" width="500px" height="400px" allowfullscreen="true" allowscriptaccess="always" quality="high" bgcolor="#000000" name="playerid" style="" src="http://www.youtube.com/v/LpbzbyGjJGE?enablejsapi=1&version=3&playerapiid=ytplayer" type="application/x-shockwave-flash">
</body>
</html>