2015-06-10 09:37:07 -04:00
|
|
|
|
(function () {
|
|
|
|
|
|
2015-07-05 14:34:52 -04:00
|
|
|
|
function vlcRenderer(options) {
|
2015-06-10 09:37:07 -04:00
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
function onEnded() {
|
2015-06-29 21:56:25 -04:00
|
|
|
|
Events.trigger(self, 'ended');
|
2015-06-10 09:37:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onTimeUpdate() {
|
2015-06-29 21:56:25 -04:00
|
|
|
|
Events.trigger(self, 'timeupdate');
|
2015-06-10 09:37:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onVolumeChange() {
|
2015-06-29 21:56:25 -04:00
|
|
|
|
Events.trigger(self, 'volumechange');
|
2015-06-10 09:37:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onPlaying() {
|
2015-06-29 21:56:25 -04:00
|
|
|
|
Events.trigger(self, 'playing');
|
2015-06-10 09:37:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onPlay() {
|
2015-06-29 21:56:25 -04:00
|
|
|
|
Events.trigger(self, 'play');
|
2015-06-10 09:37:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onPause() {
|
2015-06-29 21:56:25 -04:00
|
|
|
|
Events.trigger(self, 'pause');
|
2015-06-10 09:37:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onClick() {
|
2015-06-29 21:56:25 -04:00
|
|
|
|
Events.trigger(self, 'click');
|
2015-06-10 09:37:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onDblClick() {
|
2015-06-29 21:56:25 -04:00
|
|
|
|
Events.trigger(self, 'dblclick');
|
2015-06-10 09:37:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onError() {
|
|
|
|
|
|
|
|
|
|
var errorCode = this.error ? this.error.code : '';
|
2015-06-26 23:27:38 -04:00
|
|
|
|
Logger.log('Media element error code: ' + errorCode);
|
2015-06-10 09:37:07 -04:00
|
|
|
|
|
2015-06-29 21:56:25 -04:00
|
|
|
|
Events.trigger(self, 'error');
|
2015-06-10 09:37:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var playerState = {};
|
|
|
|
|
|
|
|
|
|
self.currentTime = function (val) {
|
|
|
|
|
|
|
|
|
|
if (val != null) {
|
2015-06-10 23:01:41 -04:00
|
|
|
|
AndroidVlcPlayer.sendVlcCommand("setposition", val.toString());
|
2015-06-10 09:37:07 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return playerState.currentTime;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.duration = function (val) {
|
|
|
|
|
|
|
|
|
|
if (playerState) {
|
|
|
|
|
return playerState.duration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-10 23:01:41 -04:00
|
|
|
|
self.stop = function () {
|
|
|
|
|
AndroidVlcPlayer.sendVlcCommand("stop", null);
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-10 09:37:07 -04:00
|
|
|
|
self.pause = function () {
|
2015-06-10 23:01:41 -04:00
|
|
|
|
AndroidVlcPlayer.sendVlcCommand("pause", null);
|
2015-06-10 09:37:07 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.unpause = function () {
|
2015-06-10 23:01:41 -04:00
|
|
|
|
AndroidVlcPlayer.sendVlcCommand("unpause", null);
|
2015-06-10 09:37:07 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.volume = function (val) {
|
|
|
|
|
if (playerState) {
|
|
|
|
|
if (val != null) {
|
2015-06-10 23:01:41 -04:00
|
|
|
|
AndroidVlcPlayer.sendVlcCommand("setvolume", (val * 100).toString());
|
2015-06-10 09:37:07 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return playerState.volume;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-07-06 03:06:09 -04:00
|
|
|
|
self.setCurrentSrc = function (val, tracks, item, mediaSource) {
|
2015-06-10 09:37:07 -04:00
|
|
|
|
|
|
|
|
|
if (!val) {
|
|
|
|
|
self.destroy();
|
2015-06-10 23:01:41 -04:00
|
|
|
|
return;
|
2015-06-10 09:37:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-08 12:10:34 -04:00
|
|
|
|
var tIndex = val.indexOf('#t=');
|
|
|
|
|
var startPosMs = 0;
|
|
|
|
|
|
|
|
|
|
if (tIndex != -1) {
|
|
|
|
|
startPosMs = val.substring(tIndex + 3);
|
|
|
|
|
startPosMs = parseFloat(startPosMs) * 1000;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 14:34:52 -04:00
|
|
|
|
if (options.type == 'audio') {
|
2015-06-23 18:13:06 -04:00
|
|
|
|
|
|
|
|
|
AndroidVlcPlayer.playAudioVlc(val, JSON.stringify(item), JSON.stringify(mediaSource), posterUrl);
|
2015-06-10 09:37:07 -04:00
|
|
|
|
} else {
|
2015-07-08 12:10:34 -04:00
|
|
|
|
|
|
|
|
|
var playbackStartInfo = {};
|
|
|
|
|
|
|
|
|
|
AndroidVlcPlayer.playVideoVlc(val, startPosMs, item.Name, JSON.stringify(mediaSource), JSON.stringify(playbackStartInfo));
|
2015-06-10 09:37:07 -04:00
|
|
|
|
}
|
2015-06-10 23:01:41 -04:00
|
|
|
|
|
|
|
|
|
playerState.currentSrc = val;
|
2015-06-10 09:37:07 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.currentSrc = function () {
|
|
|
|
|
if (playerState) {
|
|
|
|
|
return playerState.currentSrc;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.paused = function () {
|
|
|
|
|
|
|
|
|
|
if (playerState) {
|
|
|
|
|
return playerState.paused;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-25 17:50:56 -04:00
|
|
|
|
self.cleanup = function (destroyRenderer) {
|
|
|
|
|
|
|
|
|
|
if (destroyRenderer !== false) {
|
|
|
|
|
AndroidVlcPlayer.destroyVlc();
|
|
|
|
|
}
|
2015-06-10 09:37:07 -04:00
|
|
|
|
|
|
|
|
|
playerState = {};
|
|
|
|
|
};
|
|
|
|
|
|
2015-07-05 14:34:52 -04:00
|
|
|
|
self.enableCustomVideoControls = function () {
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-23 18:13:06 -04:00
|
|
|
|
var posterUrl;
|
2015-06-10 09:37:07 -04:00
|
|
|
|
self.setPoster = function (url) {
|
2015-06-23 18:13:06 -04:00
|
|
|
|
posterUrl = url;
|
2015-06-10 09:37:07 -04:00
|
|
|
|
};
|
2015-06-10 23:01:41 -04:00
|
|
|
|
|
|
|
|
|
self.report = function (eventName, duration, position, isPaused, volume) {
|
|
|
|
|
|
|
|
|
|
var state = playerState;
|
2015-06-11 02:27:05 -04:00
|
|
|
|
|
2015-06-10 23:01:41 -04:00
|
|
|
|
state.duration = duration;
|
|
|
|
|
state.currentTime = position;
|
2015-06-11 02:27:05 -04:00
|
|
|
|
state.paused = isPaused;
|
2015-06-10 23:01:41 -04:00
|
|
|
|
state.volume = (volume || 0) / 100;
|
|
|
|
|
|
|
|
|
|
if (eventName == 'playbackstop') {
|
|
|
|
|
onEnded();
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == 'volumechange') {
|
|
|
|
|
onVolumeChange();
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == 'positionchange') {
|
|
|
|
|
onTimeUpdate();
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == 'paused') {
|
|
|
|
|
onPause();
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == 'unpaused') {
|
|
|
|
|
onPlaying();
|
|
|
|
|
}
|
|
|
|
|
else if (eventName == 'playing') {
|
|
|
|
|
onPlaying();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-07-05 14:34:52 -04:00
|
|
|
|
self.init = function () {
|
|
|
|
|
|
|
|
|
|
var deferred = DeferredBuilder.Deferred();
|
|
|
|
|
deferred.resolve();
|
|
|
|
|
return deferred.promise();
|
|
|
|
|
};
|
|
|
|
|
|
2015-07-08 12:10:34 -04:00
|
|
|
|
self.onActivityClosed = function (wasStopped, hasError, endPositionMs) {
|
|
|
|
|
|
|
|
|
|
playerState.currentTime = endPositionMs;
|
|
|
|
|
|
|
|
|
|
if (wasStopped) {
|
|
|
|
|
MediaPlayer.stop(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.report('playbackstop', playerState.duration, endPositionMs, false, 100);
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-10 23:01:41 -04:00
|
|
|
|
window.AudioRenderer.Current = self;
|
2015-07-05 14:34:52 -04:00
|
|
|
|
window.VideoRenderer.Current = self;
|
2015-06-10 09:37:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-05 14:34:52 -04:00
|
|
|
|
window.AudioRenderer = function (options) {
|
|
|
|
|
options = options || {};
|
|
|
|
|
options.type = 'audio';
|
|
|
|
|
|
|
|
|
|
return new vlcRenderer(options);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.VideoRenderer = function (options) {
|
|
|
|
|
options = options || {};
|
|
|
|
|
options.type = 'video';
|
|
|
|
|
|
|
|
|
|
return new vlcRenderer(options);
|
|
|
|
|
};
|
2015-06-10 09:37:07 -04:00
|
|
|
|
|
|
|
|
|
})();
|