brandly / angular-youtube-embed

:tv: Embed a YouTube player with a simple directive
http://brandly.github.io/angular-youtube-embed/
MIT License
510 stars 147 forks source link

Show time of video in real time #148

Open Agusteen opened 7 years ago

Agusteen commented 7 years ago

Hello, first of all, thanks for this, it's very useful!...

I want to show the current time of the video, with the form: "min:sec", and this update it constantly in my HTML. I've been trying with a $watch of 'player.getCurrentTime()' but I didn't succeed. Is there a form od add it this watcher like a directive?.

From already thank you very much.

brandly commented 7 years ago

hey! thanks for the kind words.

there's some discussion about this in #80 you could check out.

currently, there's no super simple answer. hope you get things working! 🌟

Agusteen commented 7 years ago

With a $watch not working... I think that I found a better solution, share it here for somebody who serves: I use angular service $interval, the function "timer" take as parameter the name of player and this refresh the time every 1 second. Here the documentation of $interval: https://docs.angularjs.org/api/ng/service/$interval

var timer = function(video) {
        var promise = $interval(function() {  
          $scope. currentTime = video.getCurrentTime(); //this show current time in my view 
          if(condition to end interval)) {
            $interval.cancel(promise);            
          }
        }, 1000);
      }

timer($scope.myPlayer);

I hope this helps someone!!

brandly commented 7 years ago

thanks for sharing!