Reputation: 171
Go to an url such as:
https://www.youtube.com/embed/zvCBSSwgtg4
and open the chrome console. I want to know what javascript command will play the youtube video and what javascript command will pause the youtube video.
I've tried using the profiler and inspector to find these commands but they are too well hidden. If someone is really good at javascript debugging, this would be a big help. Thanks!
Yes, I know youtube has API for iframes, but my use case is different.
Upvotes: 3
Views: 6391
Reputation: 1827
For HTML5 youtube player simply doing:
document.getElementsByTagName('video')[0].play()
document.getElementsByTagName('video')[0].pause()
I recently created a chrome extension for same: https://chrome.google.com/webstore/detail/youtube-playback-control/okbcoijdeebocmahlanbfemnckjonfnh
Hope it helps.
Upvotes: 12
Reputation: 1524
Have you tried triggering a click on the actual play/pause button?
document.getElementsByClassName('ytp-play-button')[0].click();
Upvotes: 7
Reputation: 46
This should be easy to do, just check for event attached to the button that you pushed and then trigger them manually using.
For example if the button has a jQuery event handler use:
http://api.jquery.com/trigger/
Or if it is a native JavaScript event you can use:
How to trigger event in JavaScript?
Upvotes: 1