Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
145
rated 0 times [  149] [ 4]  / answers: 1 / hits: 10185  / 11 Years ago, tue, december 17, 2013, 12:00:00

My custom HTML5 video play is almost complete, I'm just having a slight issue with the Stop button which essentially is a pause button that just resets the video to the beginning.



Below is my code (albeit a little messy);



<script type=text/javascript>
function stopPlayer() {
var mediaPlayer;

mediaPlayer = document.getElementById('media-video');
mediaPlayer.controls = false;

mediaPlayer.pause();
mediaPlayer.currentTime = 0;

if ( mediaPlayer.pause == true ) {
$('.pause-btn').hide();
$('.play-btn').show();
}

}

function playPlayer() {
var mediaPlayer;

mediaPlayer = document.getElementById('media-video');
mediaPlayer.controls = false;

mediaPlayer.play();
}

function playPause() {
var mediaPlayer = document.getElementById('media-video');
if (mediaPlayer.paused) {
mediaPlayer.play();
$('.pause-btn').show();
$('.play-btn').hide();
} else {
mediaPlayer.pause();
$('.play-btn').show();
$('.pause-btn').hide();
}

}

</script>


The code in question is inside the stopPlayer(); function -



if ( mediaPlayer.pause == true ) {
$('.pause-btn').hide();
$('.play-btn').show();
}


What I'm trying to do is check to see if the video is Stopped with the StopPlayer function and then hide the pause button and show the play button. As these need to be reset when the the video is stopped.



Currently if you press the stop button, the pause button is still there.



Any advice would be great :)



Edit: Fixed @MelanciaUK suggested I removed the == true on the if statement, which fixed my issue. Thanks!


More From » jquery

 Answers
6

Maybe it's just a little conditional/property mistake.



Try to replace:



mediaPlayer.pause == true



With:



mediaPlayer.paused


[#49468] Monday, December 16, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jarettajb

Total Points: 678
Total Questions: 94
Total Answers: 90

Location: Guernsey
Member since Tue, Jul 6, 2021
3 Years ago
;