-1

i Cant To Do Random Pause In HTML5 Video Player . Anybody Can Help Me?

function vidSeek(){
var seekto = vid.duration * (seekslider.value / 100);
vid.currentTime = seekto;
var currentsec = Math.random();
if(currentsec = 3){
    vid.pause();
    console.log("STOP");
}
  • 1
    It's been a while with javascript, but `if(currentsec = 3){` ... looks odd to me. Should be `==` even in javascript, no? – Fildor Dec 03 '14 at 15:28
  • 1
    Math.random() will give you a number (float) between 0 and 1... Your condition doesn't make any sense. And @Fildor is right, == is the way to go to make a comparison. – johnkork Dec 03 '14 at 15:32
  • What are you trying to accomplish? Use previous two comments to fix your code – Vsevolod Goloviznin Dec 03 '14 at 15:39

1 Answers1

1

Here is what I suggest you do and why:

function videoSeek(){
    var video = document.getElementById("IDofVideo"); //Get video player

    //stuff happens here...

    var currentsec = Math.floor(Math.random() * 4) + 1; //Gives you # between 1 and 4.
    if(currentsec == 3){
        video.pause();
        console.log("STOP");
    }
}

First, I don't know what your variable vid is or how you got it so I'm showing you how I would set it.

Second, the random number you have should definitely be changed, like @johnkork stated. I don't know the range of numbers you need so I just did an example of 1-4.

Third, the if statement must use either == or === for comparison like @Fildor stated. Here is a good article explaining why Which equals operator (== vs ===) should be used in JavaScript comparisons?

And last, assuming vid was properly set and everything, your .pause(); call should work.

I don't really see what you are trying to accomplish with this, so having a goal would help display what you need to do. Hopefully this helps.

Community
  • 1
  • 1
Termato
  • 1,556
  • 1
  • 16
  • 33