1 window.DailymotionPlayer = class DailymotionPlayer extends Player
3 if not (this instanceof DailymotionPlayer)
4 return new DailymotionPlayer(data)
6 @setMediaProperties(data)
7 @initialVolumeSet = false
8 @playbackReadyCb = null
10 waitUntilDefined(window, 'DM', =>
15 wmode: if USEROPTS.wmode_transparent then 'transparent' else 'opaque'
18 quality = @mapQuality(USEROPTS.default_quality)
20 params.quality = quality
22 @dm = DM.player('ytapiplayer',
24 width: parseInt(VWIDTH, 10)
25 height: parseInt(VHEIGHT, 10)
29 @dm.addEventListener('apiready', =>
31 @dm.addEventListener('ended', ->
33 socket.emit('playNext')
36 @dm.addEventListener('pause', =>
42 @dm.addEventListener('playing', =>
47 if not @initialVolumeSet
49 @initialVolumeSet = true
52 # Once the video stops, the internal state of the player
53 # becomes unusable and attempting to load() will corrupt it and
54 # crash the player with an error. As a short–medium term
55 # workaround, mark the player as "not ready" until the next
56 # playback_ready event
57 @dm.addEventListener('video_end', =>
60 @dm.addEventListener('playback_ready', =>
64 @playbackReadyCb = null
70 @setMediaProperties(data)
73 @dm.seek(data.currentTime)
75 # TODO: Player::load() needs to be made asynchronous in the future
76 console.log('Warning: load() called before DM is ready, queueing callback')
77 @playbackReadyCb = () =>
79 @dm.seek(data.currentTime)
81 console.error('WTF? DailymotionPlayer::load() called but @dm is undefined')
97 setVolume: (volume) ->
113 # There was once a bug in Dailymotion where it sometimes gave back
114 # volumes in the wrong range. Not sure if this is still a necessary
122 mapQuality: (quality) ->
123 switch String(quality)
124 when '240', '480', '720', '1080' then String(quality)
125 when '360' then '380'
126 when 'best' then '1080'
131 @dm.destroy('ytapiplayer')