fix: play segments

This commit is contained in:
Rogee
2024-12-28 16:05:25 +08:00
parent dae2941168
commit cee14cb3fd
5 changed files with 22 additions and 22 deletions

View File

@@ -129,11 +129,11 @@ const loadMedia = (hash) => {
const play = (hash, type) => {
const player = document.getElementById("video");
const source = `/v1/medias/${hash}/${type}`;
const source = `/v1/medias/${hash}/${type}?token=${__GA}`;
if (Hls.isSupported()) {
var hls = new Hls({
xhrSetup: function (xhr, url) {
xhr.setRequestHeader("Authorization", "Bearer " + __GA);
xhr.withCredentials = true;
},
});
hls.loadSource(source);
@@ -142,19 +142,10 @@ const play = (hash, type) => {
player.play();
});
} else if (player.canPlayType("application/vnd.apple.mpegurl")) {
var xhr = new XMLHttpRequest();
xhr.open('GET', source, true);
xhr.setRequestHeader("Authorization", "Bearer " + __GA);
xhr.responseType = 'blob';
xhr.onload = function () {
if (xhr.status === 200) {
player.src = URL.createObjectURL(xhr.response);
player.addEventListener("loadedmetadata", function () {
player.play();
});
}
};
xhr.send();
player.src = source;
player.addEventListener("loadedmetadata", function () {
player.play();
});
}
};
</script>