Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

Vue how to get duration of each youtube video in v-for loop

$
0
0

In my vue-app I'm using the VueToube-package. So far it works fine, but I want to display the duration of each video so I tried to do this:

<div v-for="(review, index) in reviews" :key="index"><youtube      :video-id="video"      :width="420"      :ref="'video'+ index"      @ready="ready"></youtube><div>      {{ time }}</div></div>

Then I'm doing this:

data(){  time: '00:00'},methods: {  ready(player) {  Object.keys(this.$refs).forEach((el) => {    this.$refs[el][0].player.getDuration().then((result) => {      this.videoDuration(result);    });  });},videoDuration(time) {  time = Math.round(time);  let minutes = Math.floor(time / 60);  let seconds = time - minutes * 60;  seconds = seconds < 10 ? "0" + seconds : seconds;  minutes = minutes < 10 ? "0" + minutes : minutes;  this.time =  minutes +":" + seconds;},

This does not really work since the results is each video having the same length/duration.

What am I doing wrong?


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>