mirror of
https://github.com/zedeus/nitter
synced 2026-09-05 22:59:31 +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
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
function playVideo(overlay) {
|
||||
const video = overlay.parentElement.querySelector('video');
|
||||
const url = video.getAttribute("data-url");
|
||||
const startTime = parseFloat(video.getAttribute("data-start") || "0");
|
||||
video.setAttribute("controls", "");
|
||||
function playMedia(overlay, tagName) {
|
||||
const media = overlay.parentElement.querySelector(tagName);
|
||||
const url = media.getAttribute("data-url");
|
||||
const startTime = parseFloat(media.getAttribute("data-start") || "0");
|
||||
media.setAttribute("controls", "");
|
||||
overlay.style.display = "none";
|
||||
|
||||
if (Hls.isSupported()) {
|
||||
var hls = new Hls({autoStartLoad: false});
|
||||
hls.loadSource(url);
|
||||
hls.attachMedia(video);
|
||||
hls.attachMedia(media);
|
||||
hls.on(Hls.Events.MANIFEST_PARSED, function () {
|
||||
hls.loadLevel = hls.levels.length - 1;
|
||||
hls.startLoad(startTime);
|
||||
video.play();
|
||||
media.play();
|
||||
});
|
||||
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
||||
video.src = url;
|
||||
video.addEventListener('canplay', function() {
|
||||
if (startTime > 0) video.currentTime = startTime;
|
||||
video.play();
|
||||
} else if (media.canPlayType('application/vnd.apple.mpegurl')) {
|
||||
media.src = url;
|
||||
media.addEventListener('canplay', function() {
|
||||
if (startTime > 0) media.currentTime = startTime;
|
||||
media.play();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function playVideo(overlay) { playMedia(overlay, 'video'); }
|
||||
function playAudio(overlay) { playMedia(overlay, 'audio'); }
|
||||
// @license-end
|
||||
|
|
|
|||
Loading…
Reference in a new issue