Skip to content

Commit

Permalink
Merge pull request #22 from dailymotion/next
Browse files Browse the repository at this point in the history
  • Loading branch information
dharFr committed Jul 2, 2015
2 parents 2c5629d + 54f3a57 commit 869943a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 15 deletions.
9 changes: 7 additions & 2 deletions Makefile
@@ -1,14 +1,19 @@
PLAYER_FILES := src/core/prelude.js src/common/array.js src/core/player.js src/core/epilogue.js src/core/qs.js

FILES := src/third-party/json2.js src/core/prelude.js src/core/json.js src/common/array.js \
src/core/cookie.js src/core/event.js src/core/init.js src/core/qs.js src/core/api.js \
src/core/cookie.js src/core/event.js src/core/init.js src/core/epilogue.js src/core/qs.js src/core/api.js \
src/core/auth.js src/core/xdcom.js src/core/player.js
COMPRESSOR_BIN := yuicompressor
MXMLC_BIN := mxmlc

all: all.js xdcom.swf
all: all.js player_api.js xdcom.swf

all.js: $(FILES)
cat $(FILES) | $(COMPRESSOR_BIN) --type js -o $@

player_api.js: $(PLAYER_FILES)
cat $(PLAYER_FILES) | $(COMPRESSOR_BIN) --type js -o $@

xdcom.swf: src/core/xdcom.as
$(MXMLC_BIN) --strict -optimize -debug=true -static-link-runtime-shared-libraries=true -o $@ -- src/core/xdcom.as

6 changes: 6 additions & 0 deletions src/core/epilogue.js
@@ -0,0 +1,6 @@
// this is useful when the library is being loaded asynchronously
//
// we do it in a setTimeout to wait until the current event loop as finished.
// this allows potential library code being included below this block (possible
// when being served from an automatically combined version)
window.setTimeout(function() { if (window.dmAsyncInit) { dmAsyncInit(); }}, 0);
9 changes: 1 addition & 8 deletions src/core/init.js
Expand Up @@ -73,11 +73,4 @@ DM.provide('',
}
}
}
});

// this is useful when the library is being loaded asynchronously
//
// we do it in a setTimeout to wait until the current event loop as finished.
// this allows potential library code being included below this block (possible
// when being served from an automatically combined version)
window.setTimeout(function() { if (window.dmAsyncInit) { dmAsyncInit(); }}, 0);
});
10 changes: 10 additions & 0 deletions src/core/player.js
Expand Up @@ -62,6 +62,10 @@ DM.provide('Player',
paused: true,
fullscreen: false,
rebuffering: false,
qualities: [],
quality: undefined,
subtitles: [],
subtitle: undefined,

play: function() {this.api('play');},
togglePlay: function() {this.api('toggle-play');},
Expand All @@ -71,6 +75,8 @@ DM.provide('Player',
setMuted: function(muted) {this.api('muted', muted);},
toggleMuted: function() {this.api('toggle-muted');},
setVolume: function(volume) {this.api('volume', volume);},
setQuality: function(quality) {this.api('quality', quality);},
setSubtitle: function(subtitle) {this.api('subtitle', subtitle);},
setFullscreen: function(fullscreen) {this.api('fullscreen', fullscreen);},
watchOnSite: function(muted) {this.api('watch-on-site');},

Expand Down Expand Up @@ -303,6 +309,10 @@ DM.provide('Player',
case 'pause': this.paused = true; break;
case 'error': this.error = {code: event.code, title: event.title, message: event.message}; break;
case 'rebuffer': this.rebuffering = DM.parseBool(event.rebuffering); break;
case 'qualitiesavailable': this.qualities = event.qualities; break;
case 'qualitychange': this.quality = event.quality; break;
case 'subtitlesavailable': this.subtitles = event.subtitles; break;
case 'subtitlechange': this.subtitle = event.subtitle; break;
}

this._dispatch(event.event);
Expand Down
16 changes: 14 additions & 2 deletions src/core/qs.js
Expand Up @@ -69,14 +69,26 @@ DM.provide('QS',
params = {},
parts = str.split('&'),
i,
pair;
pair,
key,
val;

for (i = 0; i < parts.length; i++)
{
pair = parts[i].split('=', 2);
if (pair && pair[0])
{
params[decode(pair[0])] = pair[1] ? decode(pair[1].replace(/\+/g, '%20')) : '';
key = decode(pair[0]);
val = pair[1] ? decode(pair[1].replace(/\+/g, '%20')) : '';
if (/\[\]$/.test(key))
{
key = key.slice(0,-2);
(params[key] ? params[key] : params[key] = []).push(val);
}
else
{
params[key] = val;
}
}
}

Expand Down
22 changes: 19 additions & 3 deletions tests/player.html
Expand Up @@ -40,6 +40,10 @@
<span style="float: right">Platform: <script>document.write(navigator.platform)</script></span>
</div>
<div>
<input type=button value=quality prompt="Quality" default=240>
<input type=button value=subtitle prompt="Subtitle" default=none>
</div>
<div>
<input type=button value=toggle-mute>
<input type=button value=mute>
<input type=button value=unmute>
Expand Down Expand Up @@ -67,7 +71,7 @@
//DM.XDCom._swfPath = '../xdcom.swf'

var params = {html: "0"},
video = 'x6q96t',
video = 'xwr14q',
player = DM.player($('#player').get(0), {video: video, width: '100%', height: '100%', params: params});

$('input[name=html]:checkbox').change(function()
Expand Down Expand Up @@ -104,7 +108,7 @@
$('<li class=out>&lt;- ' + cmd + (arg ? '=' + arg : '') + '</li>').prependTo('#console');
$('#player').get(0).api(cmd, arg);
});
$(player).bind( 'apiready play playing canplay canplaythrough loadedmetadata timeupdate progress seeking seeked volumechange durationchange pause ended error fullscreenchange ad_start ad_timeupdate ad_play ad_pause ad_end', function(e)
$(player).bind( 'apiready play playing canplay canplaythrough loadedmetadata timeupdate progress seeking seeked volumechange durationchange pause ended error fullscreenchange qualitiesavailable qualitychange subtitlesavailable subtitlechange ad_start ad_timeupdate ad_play ad_pause ad_end', function(e)
{
var data = {}, player = e.target;
switch (e.type)
Expand Down Expand Up @@ -134,14 +138,26 @@
data['volume'] = player.volume;
data['muted'] = player.muted;
break;
case 'qualitiesavailable':
data['qualities'] = player.qualities;
break;
case 'qualitychange':
data['quality'] = player.quality;
break;
case 'subtitlesavailable':
data['subtitles'] = player.subtitles;
break;
case 'subtitlechange':
data['subtitle'] = player.subtitle;
break;

case 'error':
data = player.error;
break;
}

if ($.inArray(e.type, ['play', 'playing', 'pause', 'ad_play', 'ad_pause']) !== -1) $('#status').html(e.type);
var line = $('<li class=in>-&gt; ' + e.type + ' ' + ($.param(data).replace(/&/g, ' ')) + '</li>').prependTo('#console');
var line = $('<li class=in>-&gt; ' + e.type + ' ' + JSON.stringify(data) + '</li>').prependTo('#console');
if ($.inArray(e.type, ['timeupdate', 'progress', 'ad_timeupdate']) !== -1) line.addClass('minor');
if (e.type == 'error') line.addClass('fatal');
});
Expand Down

0 comments on commit 869943a

Please sign in to comment.