mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
add hlsjs
This commit is contained in:
parent
93cc99f0ec
commit
b78ef8cbe5
2 changed files with 50 additions and 77 deletions
|
@ -1,7 +1,7 @@
|
||||||
(function () {
|
(function () {
|
||||||
|
|
||||||
var supportsTextTracks;
|
var supportsTextTracks;
|
||||||
var isViblastStarted;
|
var hlsPlayer;
|
||||||
var requiresSettingStartTimeOnStart;
|
var requiresSettingStartTimeOnStart;
|
||||||
|
|
||||||
function htmlMediaRenderer(options) {
|
function htmlMediaRenderer(options) {
|
||||||
|
@ -31,20 +31,20 @@
|
||||||
|
|
||||||
function onTimeUpdate() {
|
function onTimeUpdate() {
|
||||||
|
|
||||||
if (isViblastStarted) {
|
//if (isViblastStarted) {
|
||||||
|
|
||||||
// This is a workaround for viblast not stopping playback at the end
|
// // This is a workaround for viblast not stopping playback at the end
|
||||||
var time = this.currentTime;
|
// var time = this.currentTime;
|
||||||
var duration = this.duration;
|
// var duration = this.duration;
|
||||||
|
|
||||||
if (duration) {
|
// if (duration) {
|
||||||
if (time >= (duration - 1)) {
|
// if (time >= (duration - 1)) {
|
||||||
|
|
||||||
//onEnded();
|
// //onEnded();
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
$(self).trigger('timeupdate');
|
$(self).trigger('timeupdate');
|
||||||
}
|
}
|
||||||
|
@ -88,56 +88,18 @@
|
||||||
|
|
||||||
function onLoadedMetadata() {
|
function onLoadedMetadata() {
|
||||||
|
|
||||||
if (!isViblastStarted) {
|
if (!hlsPlayer) {
|
||||||
this.play();
|
this.play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function requireViblast(callback) {
|
function requireHlsPlayer(callback) {
|
||||||
require(['thirdparty/viblast/viblast.js'], function () {
|
require(['thirdparty/hls.min.js'], function (hls) {
|
||||||
|
window.Hls = hls;
|
||||||
if (htmlMediaRenderer.customViblastKey) {
|
|
||||||
callback();
|
|
||||||
} else {
|
|
||||||
downloadViblastKey(callback);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function downloadViblastKey(callback) {
|
|
||||||
|
|
||||||
var savedKeyPropertyName = 'vbk';
|
|
||||||
var savedKey = appStorage.getItem(savedKeyPropertyName);
|
|
||||||
|
|
||||||
if (savedKey) {
|
|
||||||
htmlMediaRenderer.customViblastKey = savedKey;
|
|
||||||
callback();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var headers = {};
|
|
||||||
headers['X-Emby-Token'] = 'EMBY_SERVER';
|
|
||||||
|
|
||||||
HttpClient.send({
|
|
||||||
type: 'GET',
|
|
||||||
url: 'https://mb3admin.com/admin/service/registration/getViBlastKey',
|
|
||||||
headers: headers
|
|
||||||
|
|
||||||
}).done(function (key) {
|
|
||||||
|
|
||||||
appStorage.setItem(savedKeyPropertyName, key);
|
|
||||||
htmlMediaRenderer.customViblastKey = key;
|
|
||||||
callback();
|
|
||||||
}).fail(function () {
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getViblastKey() {
|
|
||||||
|
|
||||||
return htmlMediaRenderer.customViblastKey || 'N8FjNTQ3NDdhZqZhNGI5NWU5ZTI=';
|
|
||||||
}
|
|
||||||
|
|
||||||
function getStartTime(url) {
|
function getStartTime(url) {
|
||||||
|
|
||||||
var src = url;
|
var src = url;
|
||||||
|
@ -174,10 +136,16 @@
|
||||||
|
|
||||||
// Appending #t=xxx to the query string doesn't seem to work with HLS
|
// Appending #t=xxx to the query string doesn't seem to work with HLS
|
||||||
if (startPositionInSeekParam && src.indexOf('.m3u8') != -1) {
|
if (startPositionInSeekParam && src.indexOf('.m3u8') != -1) {
|
||||||
|
|
||||||
|
var delay = $.browser.safari ? 2500 : 0;
|
||||||
var element = this;
|
var element = this;
|
||||||
|
if (delay) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
element.currentTime = startPositionInSeekParam;
|
element.currentTime = startPositionInSeekParam;
|
||||||
}, 2500);
|
}, delay);
|
||||||
|
} else {
|
||||||
|
element.currentTime = startPositionInSeekParam;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,7 +184,7 @@
|
||||||
.on('error', onError)[0];
|
.on('error', onError)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
function enableViblast(src) {
|
function enableHlsPlayer(src) {
|
||||||
|
|
||||||
if (src) {
|
if (src) {
|
||||||
if (src.indexOf('.m3u8') == -1) {
|
if (src.indexOf('.m3u8') == -1) {
|
||||||
|
@ -298,18 +266,18 @@
|
||||||
if (mediaElement) {
|
if (mediaElement) {
|
||||||
mediaElement.pause();
|
mediaElement.pause();
|
||||||
|
|
||||||
if (isViblastStarted) {
|
if (hlsPlayer) {
|
||||||
_currentTime = mediaElement.currentTime;
|
_currentTime = mediaElement.currentTime;
|
||||||
|
|
||||||
// Sometimes this fails
|
// Sometimes this fails
|
||||||
try {
|
try {
|
||||||
viblast('#' + mediaElement.id).stop();
|
hlsPlayer.destroy();
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
Logger.log(err);
|
Logger.log(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
isViblastStarted = false;
|
hlsPlayer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -379,33 +347,35 @@
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
if (isViblastStarted) {
|
if (hlsPlayer) {
|
||||||
viblast('#' + elem.id).stop();
|
hlsPlayer.destroy();
|
||||||
isViblastStarted = false;
|
hlsPlayer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startTime) {
|
if (startTime) {
|
||||||
|
|
||||||
try {
|
//try {
|
||||||
elem.currentTime = startTime;
|
// elem.currentTime = startTime;
|
||||||
} catch (err) {
|
//} catch (err) {
|
||||||
// IE will throw an invalid state exception when trying to set currentTime before starting playback
|
// // IE will throw an invalid state exception when trying to set currentTime before starting playback
|
||||||
}
|
//}
|
||||||
requiresSettingStartTimeOnStart = elem.currentTime == 0;
|
//requiresSettingStartTimeOnStart = elem.currentTime == 0;
|
||||||
|
requiresSettingStartTimeOnStart = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
tracks = tracks || [];
|
tracks = tracks || [];
|
||||||
|
|
||||||
if (enableViblast(val)) {
|
if (enableHlsPlayer(val)) {
|
||||||
|
|
||||||
setTracks(elem, tracks);
|
setTracks(elem, tracks);
|
||||||
|
|
||||||
viblast('#' + elem.id).setup({
|
var hls = new Hls();
|
||||||
key: getViblastKey(),
|
hls.loadSource(val);
|
||||||
stream: val
|
hls.attachVideo(elem);
|
||||||
|
hls.on(Hls.Events.MANIFEST_PARSED, function () {
|
||||||
|
elem.play();
|
||||||
});
|
});
|
||||||
|
hlsPlayer = hls;
|
||||||
isViblastStarted = true;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -618,9 +588,9 @@
|
||||||
|
|
||||||
var deferred = DeferredBuilder.Deferred();
|
var deferred = DeferredBuilder.Deferred();
|
||||||
|
|
||||||
if (options.type == 'video' && enableViblast()) {
|
if (options.type == 'video' && enableHlsPlayer()) {
|
||||||
|
|
||||||
requireViblast(function () {
|
requireHlsPlayer(function () {
|
||||||
|
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
});
|
});
|
||||||
|
|
3
dashboard-ui/thirdparty/hls.min.js
vendored
Normal file
3
dashboard-ui/thirdparty/hls.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue