I am trying to get the duration of a video before starting jwplayer playback. I tried calling getDuration () on the onReady callback, but it returns -1. When I call getDuration () on the onPlay event callback, I get the correct value. Any ideas?
Here is my code:
<video src="movie.mp4" id="video" width="800" height="600"></video> <script type="text/javascript"> jwplayer ('video').setup ({ flashplayer: '/js/mediaplayer-5.10/player.swf', width: 600, height: 400, events: { onReady: function () { var duration = this.getDuration(); alert ('ready, duration: ' + duration); }, onPlay: function (state) { alert ('play, duration: ' + this.getDuration()); } } }); </script>
source share