2

I have an HTML5 video and I need to get some data from other elements that were dynamically created on "timeupdate", I am currently using:

var video = $('video');
video.on('timeupdate', function() {

    //get data from dynamically created elements

});

This only works with previously created elements, but once I introduce a dynamically created element it comes back as undefined, what is a better way of doing this?

Huangism
  • 16,278
  • 7
  • 48
  • 74
Edmund Rojas
  • 6,376
  • 16
  • 61
  • 92
  • This will help: http://stackoverflow.com/questions/25088565/cant-get-on-timeupdate-video-event-to-fire-after-inserting-element – kechol Sep 21 '14 at 05:53
  • I'm not sure what your problem is, and I can't reproduce it because you posted too little code. Please post more code to reproduce the problem, of even better: reproduce it in a jsFiddle so we can debug it. – Stephan Muller Sep 21 '14 at 15:11
  • how you create the dinamic content? – inye Sep 24 '14 at 18:11

1 Answers1

0

Not enough code, but I think I understand correctly.

The problem is in video tag. Looks like you define sources like:

<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>

So if you change sources video in <source> tag, you will get an old source or undefined.

The correct and working way to dinamically change video source is to change src attribute of <video> tag, for example:

$('#video').attr('src', new_source);
$('#video').get(0).play();
Bulkin
  • 1,020
  • 12
  • 27