admin管理员组文章数量:1432401
My custom HTML5 video play is almost plete, 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!
My custom HTML5 video play is almost plete, 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!
Share Improve this question edited Dec 17, 2013 at 10:26 rowefx asked Dec 17, 2013 at 10:15 rowefxrowefx 2652 gold badges9 silver badges26 bronze badges 4-
This
mediaPlayer.pause == true
shouldn't be justmediaPlayer.paused
? – emerson.marini Commented Dec 17, 2013 at 10:24 - I need to brush up on my conditionals a little - that worked a treat :) thanks mate. – rowefx Commented Dec 17, 2013 at 10:25
- No problems. I've posted an answer. :) – emerson.marini Commented Dec 17, 2013 at 10:26
- Just seen thank you again :) – rowefx Commented Dec 17, 2013 at 10:31
1 Answer
Reset to default 2Maybe it's just a little conditional/property mistake.
Try to replace:
mediaPlayer.pause == true
With:
mediaPlayer.paused
本文标签: jqueryHTML5 Video PlayStop button with JavascriptStack Overflow
版权声明:本文标题:jquery - HTML5 Video PlayStop button with Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745572354a2664121.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论