I have multiple HTML5 videos in a slider at http://ghostpool.com/wordpress/phideo and when I click on any of the slider buttons the first video is paused using the following onclick
function.
<a href="#" onclick="pausePlayer();">LINK</a>
var htmlPlayer = document.getElementsByTagName('video')[0];
function pausePlayer() {
htmlPlayer.pause();
}
However the second video does not pause when the slider buttons are clicked. I assume the Javascript above does not work with multiple videos?
EDIT: Additionally, if clicking on the video element itself I want to toggle a play and pause function. I"m using this code, but it plays and stops all videos at once. I assume I'm not looping it correctly:
function togglePlayer() {
for(var i = 0; i < htmlPlayer.length; i++){
if ( htmlPlayer[i].paused || htmlPlayer[i].ended ) {
if ( htmlPlayer[i].ended ) { htmlPlayer[i].currentTime = 0; }
htmlPlayer[i].play();
} else {
htmlPlayer[i].pause();
}
}
}