Carlos
Carlos

Reputation: 131

How to play() a <video> injected with load() from JQuery using video.js?

you have a nice time.

I need help with this issue: I'm injecting a tag using video.js and the load() function from JQuery. But when I executed:

$('#video-hero')[0].player.play();

I get this error on console:

Uncaught TypeError: Cannot read property 'play' of undefined

I've into my code this:

$('.play').on('click',function(){
  $('#headerVideo').modal('show');});


$('#headerVideo').on('show.bs.modal', function () {
var videoSpace = $('#headerVideo .modal-dialog-video .row .col-md-12');
videoSpace.load('/assets/incl/video-header.html', function(){
  $('#video-hero')[0].player.play();
});})

Can someone help me?

Thank you:

Upvotes: 3

Views: 1637

Answers (1)

misterben
misterben

Reputation: 7821

If you are using video.js, you should use its API to play the video. The original video element will have been replaced with the video.js player div which may or may not contain a video, depending on what tech is used.

From your snippet I can't see exactly what you've got, but this would work if you had <video id="video-hero" ... that has since been initialised as a video.js player.

videojs('video-hero').play();

Upvotes: 1

Related Questions