Mikail Bayram Mikail Bayram - 4 years ago 157
TypeScript Question

Angular 2, video duration access.

Im trying to get video duration from my videos that i listed in a table. I tried to access it using @ViewChildren and was successful until one part. i get the query list but when i try accessing _results it returns undefined. Later I learned that queryList was private for some reason. Any help will be appreciated

Here is my code:

<video id="video1" #video>
<source src = "{{videos.link}}" type="video/mp4">
@ViewChildren('video') video;
ngOnInit: {
Observable.timer(1000,1000).subscribe(() => {
if(this.video && !this.isVideoLogged){
this.isVideoLogged = true;

Answer Source

You can use the loadedmetadata event:

Plunker example

<video width="480" controls #video (loadedmetadata)="onMetadata($event, video)"
  onMetadata(e, video) {
    console.log('metadata: ', e);
    console.log('duration: ', this.duration = video.duration);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download