Videogular2 Get video duration return NaN

651 Views Asked by At

I'm in an angular project with Videogular2 and I've got a problem with retrieving video duration.

The Vgapi have a duration property.

duration [read-only] :number Returns the duration in seconds.

When I'm using it. It returns Nan.

When i'm looking at source :

 * Returns the duration in seconds of the current media resource. A NaN value is returned if duration is not available, or Infinity if the media resource is streaming.
     */
    readonly duration: number;
    /**

The video is in mp4 format. the duration file meta tag is filled (1:00 minute)

I will try ogg and webm form to see if it's make the job.

Someone maybe have experience on videogular2 ?

Thanks to all :)

1

There are 1 best solutions below

0
BenYsil On BEST ANSWER
onPlayerReady(api:VgAPI) 
{
  this.api = api;
  this.api.getDefaultMedia().subscriptions.ended.subscribe(
    ($event) => { this.router.navigate(['home'])

  });
  this.api.getDefaultMedia().subscriptions.loadedMetadata.subscribe(
    ($event) => { 
  this.duration=this.api.duration;
  console.log("API  "+this.api.duration);
  });
}

when Metadata are loaded you can get duration.