How can I stop a video with Javascript in Youtube?

Situation: here, where I pressed some video.

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] Source for the part "player.stopVideo():Void"

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

Answers:

Answer

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.

Example:

<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();
Answer

The following works well, tested on wamp server. Just replace the 11-digit ID in the following line with that of the video you want to play.

http://www.youtube.com/v/***LpbzbyGjJGE***?enablejsapi=1&version=3&playerapiid=ytplayer

Good luck.

 <!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>
Answer

So this is quickest way to do it!

Open Developer Options

Hover over YouTube play button.

Press Control/Command + Shift + C

Select the Button

Add id to it.

Go to console and run the following

var x = document.getElementById('id'); x.click();

That's it!

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.