Closed Soviut closed 9 years ago
hmmm the playing
thing seems like it would interfere with more standard interfaces. like, what if x + y
is NOT greater than 10
, but then the play button gets clicked on the player?
currently, you can use player.getCurrentTime
and player.seekTo
to get and set the playback time respectively. i don't think this would work well as a two-way binding, since the playback time would be naturally updating as the video went along, and it'd be hard to tell the difference between that natural progression and you manually setting the value from a controller or something. the methods on player are more explicit, so i think those should be used, since it should lead to clearer code.
Yeah, perhaps if it was a 2-way binding for state it would work better. Likewise, a two way binding for seek position. That way if the player state changes due to a play button click, the bound variable will update accordingly. The same would go for seeking.
you can use player.currentState
to get the current state. it's just a one-way binding tho, as in, if you click the play button, it will update to playing
, but you shouldn't ever be like player.currentState = 'paused'
or something. (you should use player.pauseVideo()
)
i still don't think a two-way binding for seek position is very practical though. this directive is a wrapper around the official YouTube embed library, so there's a fair amount i'm not in full control of. as i mentioned earlier, they provide those nice methods on player
for getting/setting the seek position, which i think are appropriate.
since the video is chugging along outside the angular digest cycle, if you constantly want the current seek position, you'd basically want some kind of interval that spins while the state is playing
.
$interval(function () {
$scope.seekPosition = $scope.player.getCurrentTime();
}, 1000);
while i could include an interval like this within the directive, it just feels impractical and unnecessary for those who don't constantly need the current time.
if you're building something specific, i'd be happy to give feedback about how the directive can currently handle your use case :star2:
You're right. For some reason I thought the YouTube API had a "playing" event that returned the current play head position. I now realize I'm probably confusing it with the HTML5 video API as the YouTube API only has the "playing" state.
I use an interval to update the current time when the video is playing. Here's a couple of thoughts:
The
player
attribute is good for very precise control from the controller. However, it would be nice to be able to declaratively control the state of the player via attributes. This way, template expressions can toggle playback:Additionally, playhead position could be two-way bound to get and set playback position.