Commit bb18c854 by Prem Sichanugrist

Trigger a pause event when user click Youtube logo

This will make sure that the play button is in the paused state.

Fixes https://www.pivotaltracker.com/story/show/26236143
parent b574dcb8
...@@ -126,6 +126,14 @@ describe 'VideoPlayer', -> ...@@ -126,6 +126,14 @@ describe 'VideoPlayer', ->
it 'trigger pause event', -> it 'trigger pause event', ->
expect('pause').toHaveBeenTriggeredOn @player expect('pause').toHaveBeenTriggeredOn @player
describe 'when the video is unstarted', ->
beforeEach ->
spyOnEvent @player, 'pause'
@player.onStateChange data: YT.PlayerState.UNSTARTED
it 'trigger pause event', ->
expect('pause').toHaveBeenTriggeredOn @player
describe 'when the video is ended', -> describe 'when the video is ended', ->
beforeEach -> beforeEach ->
spyOnEvent @player, 'ended' spyOnEvent @player, 'ended'
......
class @VideoPlayer class @VideoPlayer
constructor: (@video) -> constructor: (@video) ->
# Define a missing constant of Youtube API
YT.PlayerState.UNSTARTED = -1
@currentTime = 0 @currentTime = 0
@element = $("#video_#{@video.id}") @element = $("#video_#{@video.id}")
@render() @render()
...@@ -57,7 +60,7 @@ class @VideoPlayer ...@@ -57,7 +60,7 @@ class @VideoPlayer
switch event.data switch event.data
when YT.PlayerState.PLAYING when YT.PlayerState.PLAYING
$(@).trigger('play') $(@).trigger('play')
when YT.PlayerState.PAUSED when YT.PlayerState.PAUSED, YT.PlayerState.UNSTARTED
$(@).trigger('pause') $(@).trigger('pause')
when YT.PlayerState.ENDED when YT.PlayerState.ENDED
$(@).trigger('ended') $(@).trigger('ended')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment