0

Is it possible somehow in jQuery to hide specific video or source element?

<video id="one" autoplay width="300px" height="300px">
      <source src="media/sample3.mp4" type="video/mp4" />
    </video>
    <video id="two" autoplay width="300px" height="300px">
      <source src="media/sample.mp4" />
    </video>

I would like to play sample3, for example, for 1 minute, then pause sample3, hide it, show sample.mp4 and play that video.

Any suggestons?

My code which I tryed:

var video = $('video').get(0).pause();
  if ($('video').get(0).paused) { 
    $('video').get(0).hide();
  };

but the $('video').get(0).hide(); throws Uncaught TypeError: Object #<HTMLVideoElement> has no method 'hide'

4
  • 1
    maybe setInterval() could help Commented Oct 10, 2013 at 8:37
  • make a function in which first check whether the src of the video is media/sample3.mp4.. and then change it to "media/sample.mp4".. and then make another method in which use setinterval() and pass your first function and the time after which you want to execute that function as the arguments Commented Oct 10, 2013 at 8:41
  • 1
    get(0) de-referenced your jQuery object, so that you have the “native” DOM object. While that has a paused property that you are checking for here (although you could do that with jQuery’s prop as well), it has no hide method – that is a jQuery method, not a method of native DOM elements. So in the 3rd line, you have to access the jQuery object directly, not the DOM element. Commented Oct 10, 2013 at 8:43
  • Thank you CBroe! Your solution is simple and works for me. Commented Oct 10, 2013 at 8:49

1 Answer 1

1

I would try something like this

$(document).ready(function(){
    var one = $('#one');
    var two = $('#two');
    play_sound(one);
    setTimeout(function(){
        pause_sound(one);
        one.hide();
        two.show();
        play_sound(two);
        setTimeout(function(){
            pause_sound(two);
        }, 180*1000);
    }, 60*1000);
});

function play_sound(var file){
    file.play();
}

function pause_sound(var file){
    file.pause();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.