I\'m not able to get the correct video duration/length (in seconds) of a loaded/cued video via the getDuration() method of the YouTube Player API; the same method, however,
You can use YouTube Data API to access most of the information about the video, including duration:
Demo here
When using jQuery you can use $.getJSON()
to make things easier.
Seems like YouTube JavaScript API v3 allows you to get the correct duration inside the onYouTubePlayerReady()
event. All you need to do is pass &version=3
when calling swfobject.embedSWF()
method.
Demo here