mirror of
https://github.com/zedeus/nitter
synced 2026-09-05 14:49:32 +00:00
Add audio playback support to HLS.js handler
This commit is contained in:
parent
581c6f1714
commit
17ad0fec34
1 changed files with 15 additions and 12 deletions
|
|
@ -1,27 +1,30 @@
|
||||||
// @license http://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
|
// @license http://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
function playVideo(overlay) {
|
function playMedia(overlay, tagName) {
|
||||||
const video = overlay.parentElement.querySelector('video');
|
const media = overlay.parentElement.querySelector(tagName);
|
||||||
const url = video.getAttribute("data-url");
|
const url = media.getAttribute("data-url");
|
||||||
const startTime = parseFloat(video.getAttribute("data-start") || "0");
|
const startTime = parseFloat(media.getAttribute("data-start") || "0");
|
||||||
video.setAttribute("controls", "");
|
media.setAttribute("controls", "");
|
||||||
overlay.style.display = "none";
|
overlay.style.display = "none";
|
||||||
|
|
||||||
if (Hls.isSupported()) {
|
if (Hls.isSupported()) {
|
||||||
var hls = new Hls({autoStartLoad: false});
|
var hls = new Hls({autoStartLoad: false});
|
||||||
hls.loadSource(url);
|
hls.loadSource(url);
|
||||||
hls.attachMedia(video);
|
hls.attachMedia(media);
|
||||||
hls.on(Hls.Events.MANIFEST_PARSED, function () {
|
hls.on(Hls.Events.MANIFEST_PARSED, function () {
|
||||||
hls.loadLevel = hls.levels.length - 1;
|
hls.loadLevel = hls.levels.length - 1;
|
||||||
hls.startLoad(startTime);
|
hls.startLoad(startTime);
|
||||||
video.play();
|
media.play();
|
||||||
});
|
});
|
||||||
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
} else if (media.canPlayType('application/vnd.apple.mpegurl')) {
|
||||||
video.src = url;
|
media.src = url;
|
||||||
video.addEventListener('canplay', function() {
|
media.addEventListener('canplay', function() {
|
||||||
if (startTime > 0) video.currentTime = startTime;
|
if (startTime > 0) media.currentTime = startTime;
|
||||||
video.play();
|
media.play();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function playVideo(overlay) { playMedia(overlay, 'video'); }
|
||||||
|
function playAudio(overlay) { playMedia(overlay, 'audio'); }
|
||||||
// @license-end
|
// @license-end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue