Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When viewing youtube.com, can I control the videos from Chrome Dev Console?

I want to be able to pause and play the videos from inside the JavaScript console in Chrome DevTools. Is that possible?

like image 740
Joshua Soileau Avatar asked Feb 05 '14 19:02

Joshua Soileau


3 Answers

If you are using HTML5-based player, you can interact with the <video> element directly using its DOM API, as you've been told in Toni's answer.

If you are using Flash-based player, you can interact with it using YouTube JavaScript Player API. The player element seems to have id movie_player, and I don't have any problems using API methods right on YouTube.com:

$('#movie_player').playVideo();
$('#movie_player').seekTo(60);
$('#movie_player').pauseVideo();

Also, don't get confused by $, there's no jQuery.

like image 180
izstas Avatar answered Sep 30 '22 17:09

izstas


If viewing using the HTML5-based player, then

$('.video-stream').play()
$('.video-stream').pause()

OR

$('video').play()
$('video').pause()

Refer here.

If viewing using the Flash-based player, then

player.playVideo()
player.pauseVideo()

Refer here.

like image 39
JRodDynamite Avatar answered Sep 30 '22 16:09

JRodDynamite


That would depend on if you are using html5 or the flash player.

I don't think you can talk with the flash player, but html5 is possible.

You can either send a click-event to the html5-client's buttons or use the video-element's play() and pause() methods directly.

http://www.w3schools.com/tags/ref_av_dom.asp

$("video").play();
$("video").pause();

//seems like jquery has some support of its own for these basic functions too
like image 22
Toni Avatar answered Sep 30 '22 15:09

Toni