This commit is contained in:
mattyatea 2024-05-16 06:26:15 +09:00
parent 514595c5a7
commit a6e8743071

View file

@ -5,7 +5,6 @@ SPDX-License-Identifier: AGPL-3.0-only
<template> <template>
<div <div
:id="(audio.url).slice(32).replace('-','')"
ref="playerEl" ref="playerEl"
v-hotkey="keymap" v-hotkey="keymap"
tabindex="0" tabindex="0"
@ -30,9 +29,9 @@ SPDX-License-Identifier: AGPL-3.0-only
preload="metadata" preload="metadata"
controls controls
:class="$style.nativeAudio" :class="$style.nativeAudio"
:src="audio.url"
@keydown.prevent @keydown.prevent
> >
<source :src="audio.url">
</audio> </audio>
</div> </div>
@ -40,8 +39,8 @@ SPDX-License-Identifier: AGPL-3.0-only
<audio <audio
ref="audioEl" ref="audioEl"
preload="metadata" preload="metadata"
:src="audio.url"
> >
<source :src="audio.url">
</audio> </audio>
<div :class="[$style.controlsChild, $style.controlsLeft]"> <div :class="[$style.controlsChild, $style.controlsLeft]">
<button class="_button" :class="$style.controlButton" @click="togglePlayPause"> <button class="_button" :class="$style.controlButton" @click="togglePlayPause">
@ -65,24 +64,10 @@ SPDX-License-Identifier: AGPL-3.0-only
:class="$style.volumeSeekbar" :class="$style.volumeSeekbar"
/> />
</div> </div>
{{ audioEl }}
<WaveSurferPlayer
:class="$style.seekbarRoot"
:options="{ media: audioEl,
height: 32,
waveColor: 'gray',
progressColor: 'red',
barGap: 5,
barWidth: 5,
barRadius: 8,
duration: 80,
backend: 'WebAudio'
}"
></WaveSurferPlayer>
<MkMediaRange <MkMediaRange
v-if="defaultStore.state.dataSaver.media && !hide"
v-model="rangePercent" v-model="rangePercent"
:class="$style.seekbarRoot" :class="$style.seekbarRoot"
:buffer="bufferedDataRatio"
/> />
</div> </div>
</div> </div>
@ -91,8 +76,6 @@ SPDX-License-Identifier: AGPL-3.0-only
<script lang="ts" setup> <script lang="ts" setup>
import { shallowRef, watch, computed, ref, onDeactivated, onActivated, onMounted } from 'vue'; import { shallowRef, watch, computed, ref, onDeactivated, onActivated, onMounted } from 'vue';
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import { WaveSurferPlayer } from '@meersagor/wavesurfer-vue';
import type WaveSurfer from 'wavesurfer.js';
import type { MenuItem } from '@/types/menu.js'; import type { MenuItem } from '@/types/menu.js';
import { defaultStore } from '@/store.js'; import { defaultStore } from '@/store.js';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
@ -101,6 +84,7 @@ import bytes from '@/filters/bytes.js';
import { hms } from '@/filters/hms.js'; import { hms } from '@/filters/hms.js';
import MkMediaRange from '@/components/MkMediaRange.vue'; import MkMediaRange from '@/components/MkMediaRange.vue';
import { $i, iAmModerator } from '@/account.js'; import { $i, iAmModerator } from '@/account.js';
const props = defineProps<{ const props = defineProps<{
audio: Misskey.entities.DriveFile; audio: Misskey.entities.DriveFile;
}>(); }>();
@ -148,8 +132,6 @@ const hide = ref((defaultStore.state.nsfw === 'force' || defaultStore.state.data
// Menu // Menu
const menuShowing = ref(false); const menuShowing = ref(false);
const waveSuferOptions = ref();
function showMenu(ev: MouseEvent) { function showMenu(ev: MouseEvent) {
let menu: MenuItem[] = []; let menu: MenuItem[] = [];
@ -244,7 +226,10 @@ const volume = ref(.25);
const speed = ref(1); const speed = ref(1);
const loop = ref(false); // TODO: const loop = ref(false); // TODO:
const bufferedEnd = ref(0); const bufferedEnd = ref(0);
let audioContext = new AudioContext(); const bufferedDataRatio = computed(() => {
if (!audioEl.value) return 0;
return bufferedEnd.value / audioEl.value.duration;
});
// MediaControl Events // MediaControl Events
function togglePlayPause() { function togglePlayPause() {
@ -340,7 +325,7 @@ watch(loop, (to) => {
if (audioEl.value) audioEl.value.loop = to; if (audioEl.value) audioEl.value.loop = to;
}); });
onMounted(async () => { onMounted(() => {
init(); init();
}); });