- closes #129
- closes #130
- minor cleanup
This commit is contained in:
Shiny Nematoda 2023-06-13 12:26:48 +00:00
parent 8945c11f02
commit faef667189
11 changed files with 1020 additions and 885 deletions

View file

@ -1,5 +1,6 @@
<script setup>
import { ref, watch, onMounted, onBeforeUnmount, onUnmounted } from 'vue';
import { useManifest } from '@/scripts/util.js';
import muxjs from 'mux.js';
window.muxjs = muxjs;
@ -31,22 +32,7 @@ async function Stream() {
const res = player.state,
shaka = import('shaka-player/dist/shaka-player.compiled.js');
let url, mime;
if (window.MediaSource !== undefined && res.streams.length > 0) {
const { useDash } = await import('../scripts/dash.js');
const dash = useDash(res.streams, res.duration);
url = 'data:application/dash+xml;charset=utf-8;base64,' + btoa(dash);
mime = 'application/dash+xml';
} else if (res.hls) {
url = res.hls;
mime = 'application/x-mpegURL';
} else if (res.streams.length > 0) {
url = res.streams[0].url;
mime = res.streams[0].mimeType;
}
const { url, mime } = await useManifest(res);
if (!window.audioPlayer) {
shaka
@ -54,10 +40,9 @@ async function Stream() {
.then(shaka => {
shaka.polyfill.installAll();
if (shaka.Player.isBrowserSupported) {
const audioPlayer = new shaka.Player(audio.value);
const codecs = store.getItem('codec');
if (shaka.Player.isBrowserSupported()) {
const audioPlayer = new shaka.Player(audio.value),
codecs = store.getItem('codec');
audioPlayer
.getNetworkingEngine()
@ -125,6 +110,8 @@ function destroy() {
}
}
const titleState = ['Playing', 'Paused'];
watch(
() => player.state.play,
() => {
@ -139,15 +126,13 @@ watch(
audio.value.pause();
}
const state = ['Playing', 'Paused'];
if (
document.title.startsWith(state[0] + ':') ||
document.title.startsWith(state[1] + ':')
document.title.startsWith(titleState[0] + ':') ||
document.title.startsWith(titleState[1] + ':')
)
document.title = audio.value.paused
? document.title.replace(state[0], state[1])
: document.title.replace(state[1], state[0]);
? document.title.replace(titleState[0], titleState[1])
: document.title.replace(titleState[1], titleState[0]);
},
);
@ -167,16 +152,19 @@ onMounted(() => {
if ('mediaSession' in navigator) {
navigator.mediaSession.setActionHandler('play', () => {
player.state.status = 'pause';
document.title = document.title.replace(titleState[1], titleState[0]);
audio.value.play().catch(err => {
console.log(err);
player.state.status = 'play';
document.title = document.title.replace(titleState[0], titleState[1]);
});
});
navigator.mediaSession.setActionHandler('pause', () => {
audio.value.pause();
player.state.status = 'play';
document.title = document.title.replace(titleState[0], titleState[1]);
});
navigator.mediaSession.setActionHandler('previoustrack', () => {