Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Get video duration


Hi all!

The first time I use a JW Player on my site and I ran into one problem that can not decide
a few days.
I am creating a video gallery on your site and upload videos with a brief description of each,
including the duration of the clip.
??? ??? ???:
bc.. jQuery(document).ready(function(){

jwplayer("container").setup({
flashplayer: "player.swf",
file: "http://www.youtube.com/watch?v=Dc-x4OqkhiQ",
height: 270,
width: 720,
'controlbar': 'bottom'

}).onTime(function (callback) {
var pos = parseFloat(startPos) + callback.position;
setText("elapsedText", pos.toString());
percentage = pos / callback.duration;
slider.setValue(percentage);
setText("percentageText", percentage.toString());
}).onPlay(function () {

videoLength = jwplayer().getDuration(); // here, I get the correct duration
setText("durationText", videoLength.toString()+" ??????????!OnPlay!");
slider.enable();
}).onReady(function () {
//jwplayer().play();
//jwplayer().seek(10);
videoLength = jwplayer().getDuration(); //but here I can not get the correct duration of video
setText("durationText", videoLength.toString()+" ??????????!OnReady!");
slider.enable();
//alert(videoLength);
});


function setText(id, messageText) {
document.getElementById(id).innerHTML = messageText;
}




});




Tell me please how do I get the duration of video of the event onReady. Since the duration of my
each video must be placed in a particular block. Thanks.

29 Community Answers

Ethan Feldman

JW Player Support Agent  
0 rated :

Can I see where you are running this?

JW Player

User  
0 rated :

Of course. http://s.yudzhin.ru/video. I want to get duration of video in block "Here must be duration value..."

Ethan Feldman

JW Player Support Agent  
0 rated :

With YouTube at least, you are going to just need to specify it via the “duration” variable.

JW Player

User  
0 rated :

I'm sorry, but I need to know the duration of the video immediately when the page loads

JW Player

User  
0 rated :

:(

JW Player

User  
0 rated :

I hope in the future you implement this feature

Ethan Feldman

JW Player Support Agent  
0 rated :

We can’t get it until play is pressed, so you can do some JavaScript onReady to do:

jwplayer().play();
jwplayer().pause();

This might work.

JW Player

User  
0 rated :

Unfortunately it does not work. I have tried ...

Ethan Feldman

JW Player Support Agent  
0 rated :

Can you show me where you tried this?

Ethan Feldman

JW Player Support Agent  
0 rated :

Because I have tried this, it works.

Sample:

<html>
<head>
<title>Test Page</title>
</head>
<body>
<script type="text/javascript" src="http://player.longtailvideo.com/jwplayer.js"></script>
<div id="player"></div>
<script type="text/javascript">
    jwplayer("player").setup({
            file: "http://www.longtailvideo.com/jw/upload/bunny.mp4",
            flashplayer: "http://player.longtailvideo.com/player.swf",
            width: 465,
			height: 300,
			events:{
			onReady: function() {
				jwplayer().play();
				jwplayer().pause();
				}
			}
    });
</script>
</body>
</html>

JW Player

User  
0 rated :

bc.. jQuery(document).ready(function(){
jwplayer("container").setup({
//flashplayer: "player.swf",
flashplayer: "http://player.longtailvideo.com/player.swf",
//file: "http://www.youtube.com/watch?v=Dc-x4OqkhiQ",
file: "http://www.longtailvideo.com/jw/upload/bunny.mp4",
height: 270,
width: 720,
'controlbar': 'bottom',
events:{
onReady: function() {
jwplayer().play();
jwplayer().pause();

videoLength = jwplayer().getDuration();
setText("durationText", videoLength+" ??????????!OnPlay!");
slider.enable();

}
}

});



function setText(id, messageText) {
document.getElementById(id).innerHTML = messageText;
}



});

});




Url: http://s.yudzhin.ru/video

As you can see your code returns -1

JW Player

User  
0 rated :

bc.. <script type="text/javascript">

jQuery(document).ready(function(){


jwplayer("container").setup({
//flashplayer: "player.swf",
flashplayer: "http://player.longtailvideo.com/player.swf",
//file: "http://www.youtube.com/watch?v=Dc-x4OqkhiQ",
file: "http://www.longtailvideo.com/jw/upload/bunny.mp4",
height: 270,
width: 720,
'controlbar': 'bottom',
events:{
onReady: function() {
jwplayer().play();
jwplayer().pause();
videoLength = jwplayer().getDuration();
setText("durationText", " duration = " + videoLength);
slider.enable();
}
}




});



function setText(id, messageText) {
document.getElementById(id).innerHTML = messageText;
}



});



</script>



Ethan Feldman

JW Player Support Agent  
0 rated :

Can I see where this is running? Did you try my code above? Mine definitely works!

JW Player

User  
0 rated :

Url: http://s.yudzhin.ru/video

JW Player

User  
0 rated :

http://s.yudzhin.ru/video

Ethan Feldman

JW Player Support Agent  
0 rated :

Works for me on this link.

JW Player

User  
0 rated :

Hmmmmm....What browser are you using?))

Ethan Feldman

JW Player Support Agent  
0 rated :

FF14

JW Player

User  
0 rated :

What is the duration you have? I "duration = -1"

JW Player

User  
0 rated :

I have FF14 too...and I have "duration = -1"

Ethan Feldman

JW Player Support Agent  
0 rated :

33

JW Player

User  
0 rated :

Please give me complete code where you get the value of duration?

Ethan Feldman

JW Player Support Agent  
0 rated :

<html>
<head>
<title>Test Page</title>
</head>
<body>
<script type="text/javascript" src="http://player.longtailvideo.com/jwplayer.js"></script>
<div id="player"></div>
<script type="text/javascript">
    jwplayer("player").setup({
            file: "http://www.longtailvideo.com/jw/upload/bunny.mp4",
            flashplayer: "http://player.longtailvideo.com/player.swf",
            width: 465,
height: 300,
events:{
onReady: function() {
jwplayer().play();
jwplayer().pause();
}
}
    });
</script>
</body>
</html>



There you go. 

JW Player

User  
0 rated :

Thank you Ethan for your help!For some reason your code does not work yet, but I'll deal.

Ethan Feldman

JW Player Support Agent  
0 rated :

Np

JW Player

User  
0 rated :

I understand. I just realized you are not quite right :) In fact,in the player I got the correct value of duration. I just meant that I needed to write this value in the <DIV id = 'durationText'> </DIV>. But if the duration value will be in the player then so too will be good! Thank you, Ethan!

Ethan Feldman

JW Player Support Agent  
0 rated :

Ah, I misunderstood…np!

JW Player

User  
0 rated :

hmmm I don get it...
Look here http://www.longtailvideo.com/addons/plugins/123/QualityMonitor?q=video%20effects. Video duration in controlbar set BEFORE video start playing. How this work? Is this some plugin or what?

Ethan Feldman

JW Player Support Agent  
0 rated :

The file being used here – http://developer.longtailvideo.com/player/testing/files/bitrates.xml

Has duration set ;) 653 seconds…

This question has received the maximum number of answers.