1 window.DailymotionPlayer = class DailymotionPlayer extends Player
3 if not (this instanceof DailymotionPlayer)
4 return new DailymotionPlayer(data)
6 @setMediaProperties(data)
7 @initialVolumeSet = false
9 waitUntilDefined(window, 'DM', =>
14 wmode: if USEROPTS.wmode_transparent then 'transparent' else 'opaque'
17 quality = @mapQuality(USEROPTS.default_quality)
19 params.quality = quality
21 @dm = DM.player('ytapiplayer',
23 width: parseInt(VWIDTH, 10)
24 height: parseInt(VHEIGHT, 10)
28 @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
57 @dm.addEventListener('video_end', =>
60 @dm.addEventListener('playback_ready', =>
67 @setMediaProperties(data)
68 if @dm and @dm.apiready
70 @dm.seek(data.currentTime)
72 console.error('WTF? DailymotionPlayer::load() called but dm is not ready')
88 setVolume: (volume) ->
104 # There was once a bug in Dailymotion where it sometimes gave back
105 # volumes in the wrong range. Not sure if this is still a necessary
113 mapQuality: (quality) ->
114 switch String(quality)
115 when '240', '480', '720', '1080' then String(quality)
116 when '360' then '380'
117 when 'best' then '1080'