forked from j62/ctbrec
1
0
Fork 0

Add support for MP4 videos

This commit is contained in:
0xboobface 2019-12-07 18:10:04 +01:00
parent 034fe81081
commit 402dd568f9
1 changed files with 39 additions and 27 deletions

View File

@ -203,7 +203,7 @@
<div id="player-window" class="modal">
<div class="modal-content">
<span class="close">&times;</span>
<video id="player" preload="none" controls width="100%">
<video id="player" preload="none" controls width="100%" height="800">
</video>
</div>
</div>
@ -389,32 +389,40 @@
};
function play(recording) {
if (Hls.isSupported()) {
var video = document.getElementById('player');
var hls = new Hls();
hls.attachMedia(video);
hls.on(Hls.Events.MEDIA_ATTACHED, function () {
let src = recording.playlist;
let hmacOfPath = CryptoJS.HmacSHA256(src, hmac);
src = '..' + src;
if (hmac.length > 0) {
src += "?hmac=" + hmacOfPath;
}
console.log(src);
hls.loadSource(src);
hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) {
console.log("manifest loaded, found " + data.levels.length + " quality level");
$('#player-window').css('display', 'block');
video.play();
});
});
} else {
$.notify('Loading HLS video streaming support failed', 'error');
console.log('HLS is not supported');
let src = recording.playlist;
src = '..' + src;
let hmacOfPath = CryptoJS.HmacSHA256(src, hmac);
if (hmac.length > 0) {
src += "?hmac=" + hmacOfPath;
}
if(console) console.log('Playing video from', src);
if(src.indexOf('.mp4') > 0) {
var video = document.getElementById('player');
video.src = src;
$('#player-window').css('display', 'block');
video.play();
} else {
if (Hls.isSupported()) {
var video = document.getElementById('player');
var hls = new Hls();
hls.attachMedia(video);
hls.on(Hls.Events.MEDIA_ATTACHED, function () {
console.log(src);
hls.loadSource(src);
hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) {
console.log("manifest loaded, found " + data.levels.length + " quality level");
$('#player-window').css('display', 'block');
video.play();
});
});
} else {
$.notify('Loading HLS video streaming support failed', 'error');
console.log('HLS is not supported');
}
}
}
function calculateSize(sizeInByte) {
@ -656,7 +664,11 @@
recording.ko_progressString = ko.observable(recording.progress === -1 ? '' : recording.progress);
recording.ko_size = ko.observable(calculateSize(recording.sizeInByte));
recording.ko_status = ko.observable(recording.status);
recording.playlist = '/hls' + recording.path + '/playlist.m3u8';
if (recording.path.endsWith('.mp4')) {
recording.playlist = '/hls' + recording.path;
} else {
recording.playlist = '/hls' + recording.path + '/playlist.m3u8';
}
observableRecordingsArray.push(recording);
}
}