GRAHATYL000
GRAHATYL000

Reputation: 3

How to stop a video using stop function?

Alright, I have very little programming experience and just want to make controls for video and audio pieces together on one page. I have searched a lot and can't figure it out.

var stop = function (id) {
    .pause();
    .src = '';
};

I want to pass either the audio or videos' id as the parameter in my function but I don't understand how make code that can be used with either. I can't put id.pause(); into my function to pause whatever id I put in as a parameter, so I'm confused as to how to make it work. Any help is appreciated!!

Upvotes: 0

Views: 160

Answers (3)

Sushant Yadav
Sushant Yadav

Reputation: 726

If you are passing the id then use that id to pause or play

var stop = function (id) {
    $('#'+id).pause(); // to pause the video
   .src = '';
};

Upvotes: 0

David Dennis
David Dennis

Reputation: 722

You could use JQuery:

$('#playMovie1').click(function(){
  $('#movie1').get(0).play();
      });

Or you could do something like this:

function playVid(x) { 
   var vid = document.getElementById(x).pause();  
}

Upvotes: 2

julianstark999
julianstark999

Reputation: 3616

You can use

var stop = function (htmlId) {
    var vid = document.getElementById(htmlId); 

    vid.pause();
};

Upvotes: 1

Related Questions