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

171 lines
4.0 KiB
JavaScript
Raw Normal View History

2015-06-10 06:37:07 -07:00
(function () {
function vlcRenderer(type) {
var self = this;
function onEnded() {
$(self).trigger('ended');
}
function onTimeUpdate() {
$(self).trigger('timeupdate');
}
function onVolumeChange() {
$(self).trigger('volumechange');
}
function onPlaying() {
$(self).trigger('playing');
}
function onPlay() {
$(self).trigger('play');
}
function onPause() {
$(self).trigger('pause');
}
function onClick() {
$(self).trigger('click');
}
function onDblClick() {
$(self).trigger('dblclick');
}
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
$(self).trigger('error');
}
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-06-23 15:13:06 -07:00
self.setCurrentSrc = function (val, 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
}
if (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 {
AndroidVlcPlayer.playVideoVlc(val);
}
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-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();
}
};
window.AudioRenderer.Current = self;
2015-06-10 06:37:07 -07:00
}
window.AudioRenderer = vlcRenderer;
})();