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

Question: How to detect player state change. #139

Closed thoughtpalette closed 8 years ago

thoughtpalette commented 8 years ago

Trying to run methods depending on state.

I've tried

$scope.$on('youtube.player.onStateChange', function( $event,player) $scope.$on('youtube.player.onstatechange', function( $event,player) $scope.$on('youtube.player.events.onStateChange', function( $event,player) $scope.$on('youtube.player.eventsonstatechange', function( $event,player)

I do see the event available in the player Object player.b.c.events in console.

Wondering how to capture global events on the player.

Any help would be appreciated :}

brandly commented 8 years ago

here's the code handling onStateChange: https://github.com/brandly/angular-youtube-embed/blob/master/src/angular-youtube-embed.js#L156

here are specific events you can listen for: https://github.com/brandly/angular-youtube-embed#events-and-player-controls

i believe you should also be able to $watch player.currentState, if you'd like to hear about all of them: https://github.com/brandly/angular-youtube-embed/blob/master/src/angular-youtube-embed.js#L162

hope this helps!

thoughtpalette commented 8 years ago

I think I actually may be able to do my tracking with the specific events you've linked. Was trying to migrate my old tracker script to this module.

Thanks for your help and answers! Especially on a Sunday! :}