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

165 lines
3.8 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 : '';
console.log('Media element error code: ' + errorCode);
$(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;
}
};
self.setCurrentSrc = function (val) {
if (!val) {
self.destroy();
2015-06-10 20:01:41 -07:00
return;
2015-06-10 06:37:07 -07:00
}
if (type == 'audio') {
AndroidVlcPlayer.playAudioVlc(val);
} 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;
};
self.destroy = function () {
2015-06-10 20:01:41 -07:00
AndroidVlcPlayer.destroyVlc();
2015-06-10 06:37:07 -07:00
playerState = {};
};
self.setPoster = function (url) {
};
2015-06-10 20:01:41 -07:00
self.report = function (eventName, duration, position, isPaused, volume) {
var state = playerState;
console.log('Vlc: ' + eventName + ' - ' + position + ' - ' + duration);
state.duration = duration;
state.currentTime = position;
state.isPaused = isPaused;
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;
})();