jellyfin-web/dashboard-ui/cordova/android/vlcplayer.js

196 lines
4.7 KiB
JavaScript
Raw Normal View History

2015-06-10 06:37:07 -07:00
(function () {
2015-07-05 11:34:52 -07:00
function vlcRenderer(options) {
2015-06-10 06:37:07 -07:00
var self = this;
function onEnded() {
2015-06-29 18:56:25 -07:00
Events.trigger(self, 'ended');
2015-06-10 06:37:07 -07:00
}
function onTimeUpdate() {
2015-06-29 18:56:25 -07:00
Events.trigger(self, 'timeupdate');
2015-06-10 06:37:07 -07:00
}
function onVolumeChange() {
2015-06-29 18:56:25 -07:00
Events.trigger(self, 'volumechange');
2015-06-10 06:37:07 -07:00
}
function onPlaying() {
2015-06-29 18:56:25 -07:00
Events.trigger(self, 'playing');
2015-06-10 06:37:07 -07:00
}
function onPlay() {
2015-06-29 18:56:25 -07:00
Events.trigger(self, 'play');
2015-06-10 06:37:07 -07:00
}
function onPause() {
2015-06-29 18:56:25 -07:00
Events.trigger(self, 'pause');
2015-06-10 06:37:07 -07:00
}
function onClick() {
2015-06-29 18:56:25 -07:00
Events.trigger(self, 'click');
2015-06-10 06:37:07 -07:00
}
function onDblClick() {
2015-06-29 18:56:25 -07:00
Events.trigger(self, 'dblclick');
2015-06-10 06:37:07 -07:00
}
function onError() {
var errorCode = this.error ? this.error.code : '';
2015-06-26 20:27:38 -07:00
Logger.log('Media element error code: ' + errorCode);
2015-06-10 06:37:07 -07:00
2015-06-29 18:56:25 -07:00
Events.trigger(self, 'error');
2015-06-10 06:37:07 -07:00
}
var playerState = {};
self.currentTime = function (val) {
if (val != null) {
2015-06-10 20:01:41 -07:00
AndroidVlcPlayer.sendVlcCommand("setposition", val.toString());
2015-06-10 06:37:07 -07:00
return;
}
return playerState.currentTime;
};
self.duration = function (val) {
if (playerState) {
return playerState.duration;
}
return null;
};
2015-06-10 20:01:41 -07:00
self.stop = function () {
AndroidVlcPlayer.sendVlcCommand("stop", null);
};
2015-06-10 06:37:07 -07:00
self.pause = function () {
2015-06-10 20:01:41 -07:00
AndroidVlcPlayer.sendVlcCommand("pause", null);
2015-06-10 06:37:07 -07:00
};
self.unpause = function () {
2015-06-10 20:01:41 -07:00
AndroidVlcPlayer.sendVlcCommand("unpause", null);
2015-06-10 06:37:07 -07:00
};
self.volume = function (val) {
if (playerState) {
if (val != null) {
2015-06-10 20:01:41 -07:00
AndroidVlcPlayer.sendVlcCommand("setvolume", (val * 100).toString());
2015-06-10 06:37:07 -07:00
return;
}
return playerState.volume;
}
};
2015-07-06 00:06:09 -07:00
self.setCurrentSrc = function (val, tracks, item, mediaSource) {
2015-06-10 06:37:07 -07:00
if (!val) {
self.destroy();
2015-06-10 20:01:41 -07:00
return;
2015-06-10 06:37:07 -07:00
}
2015-07-05 11:34:52 -07:00
if (options.type == 'audio') {
2015-06-23 15:13:06 -07:00
AndroidVlcPlayer.playAudioVlc(val, JSON.stringify(item), JSON.stringify(mediaSource), posterUrl);
2015-06-10 06:37:07 -07:00
} else {
2015-07-05 11:34:52 -07:00
AndroidVlcPlayer.playVideoVlc(val, JSON.stringify(item), JSON.stringify(mediaSource), posterUrl);
2015-06-10 06:37:07 -07:00
}
2015-06-10 20:01:41 -07:00
playerState.currentSrc = val;
2015-06-10 06:37:07 -07:00
};
self.currentSrc = function () {
if (playerState) {
return playerState.currentSrc;
}
};
self.paused = function () {
if (playerState) {
return playerState.paused;
}
return false;
};
2015-06-25 14:50:56 -07:00
self.cleanup = function (destroyRenderer) {
if (destroyRenderer !== false) {
AndroidVlcPlayer.destroyVlc();
}
2015-06-10 06:37:07 -07:00
playerState = {};
};
2015-07-05 11:34:52 -07:00
self.enableCustomVideoControls = function () {
return false;
};
2015-06-23 15:13:06 -07:00
var posterUrl;
2015-06-10 06:37:07 -07:00
self.setPoster = function (url) {
2015-06-23 15:13:06 -07:00
posterUrl = url;
2015-06-10 06:37:07 -07:00
};
2015-06-10 20:01:41 -07:00
self.report = function (eventName, duration, position, isPaused, volume) {
var state = playerState;
2015-06-10 23:27:05 -07:00
2015-06-10 20:01:41 -07:00
state.duration = duration;
state.currentTime = position;
2015-06-10 23:27:05 -07:00
state.paused = isPaused;
2015-06-10 20:01:41 -07: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 11:34:52 -07:00
self.init = function () {
var deferred = DeferredBuilder.Deferred();
deferred.resolve();
return deferred.promise();
};
2015-06-10 20:01:41 -07:00
window.AudioRenderer.Current = self;
2015-07-05 11:34:52 -07:00
window.VideoRenderer.Current = self;
2015-06-10 06:37:07 -07:00
}
2015-07-05 11:34:52 -07: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 06:37:07 -07:00
})();