From 229ceb66ba98964c911b99d0daf941b04d1c821c Mon Sep 17 00:00:00 2001 From: ShittyKopper Date: Mon, 15 Jan 2024 19:32:48 +0300 Subject: [PATCH] upd: initial new playback ui port based on MkMediaVideo and lightly adapted to the SkModPlayer, there's still a fair few broken parts --- .../frontend/src/components/SkMediaModule.vue | 581 +++++++++++++----- .../frontend/src/components/SkModPlayer.vue | 52 +- 2 files changed, 436 insertions(+), 197 deletions(-) diff --git a/packages/frontend/src/components/SkMediaModule.vue b/packages/frontend/src/components/SkMediaModule.vue index 15c535a9dd..5357e78223 100644 --- a/packages/frontend/src/components/SkMediaModule.vue +++ b/packages/frontend/src/components/SkMediaModule.vue @@ -4,71 +4,262 @@ SPDX-License-Identifier: AGPL-3.0-only --> diff --git a/packages/frontend/src/components/SkModPlayer.vue b/packages/frontend/src/components/SkModPlayer.vue index a12d944a0a..c86d308387 100644 --- a/packages/frontend/src/components/SkModPlayer.vue +++ b/packages/frontend/src/components/SkModPlayer.vue @@ -1,6 +1,6 @@ @@ -26,7 +27,8 @@ import { i18n } from '@/i18n.js'; import { ChiptuneJsPlayer } from '@/scripts/chiptune2.js'; const props = defineProps<{ - src: string + src: string, + alt: string | null, }>(); interface ModRow { @@ -39,7 +41,7 @@ interface ModRow { const available = ref(false); const initRow = shallowRef(); -const patternShow = ref(false); +const patternVisible = ref(false); const playing = ref(false); const modPattern = ref(); const position = ref(0); @@ -47,7 +49,7 @@ const player = shallowRef(new ChiptuneJsPlayer()); const patData = shallowRef([]); const currentPattern = ref(0); const nbChannels = ref(0); -const length = ref(1); +const duration = ref(1); const loop = ref(false); const fetching = ref(true); const error = ref(false); @@ -66,7 +68,6 @@ const volume = computed({ let buffer: ArrayBuffer|null = null; let rowHeight = 0; -let isSeeking = false; watch(currentRow, (row) => { if (!modPattern.value) { @@ -88,12 +89,24 @@ async function load() { error.value = true; fetching.value = false; } + + player.value.addHandler('onRowChange', (i: { index: number }) => { + currentRow.value = i.index; + currentPattern.value = player.value.getPattern(); + duration.value = player.value.duration(); + position.value = player.value.position() % duration.value; + requestAnimationFrame(() => display()); + }); + + player.value.addHandler('onEnded', () => { + stop(); + }); } onMounted(load); function showPattern() { - patternShow.value = !patternShow.value; + patternVisible.value = !patternVisible.value; nextTick(() => { if (playing.value) display(); else stop(); @@ -120,20 +133,6 @@ function playPause() { return; } - player.value.addHandler('onRowChange', (i: { index: number }) => { - currentRow.value = i.index; - currentPattern.value = player.value.getPattern(); - length.value = player.value.duration(); - if (!isSeeking) { - position.value = player.value.position() % length.value; - } - requestAnimationFrame(() => display()); - }); - - player.value.addHandler('onEnded', () => { - stop(); - }); - if (player.value.currentPlayingNode === null) { loading.value = true; player.value.play(buffer).then(() => { @@ -166,7 +165,6 @@ async function stop(noDisplayUpdate = false) { player.value.stop(); position.value = 0; currentRow.value = 0; - player.value.clearHandlers(); } function toggleLoop() { @@ -174,14 +172,9 @@ function toggleLoop() { player.value.repeat(loop.value ? -1 : 0); } -function initSeek() { - isSeeking = true; -} - function performSeek() { player.value.seek(position.value); display(); - isSeeking = false; } function isRowActive(i: number) { @@ -255,17 +248,18 @@ onDeactivated(() => { }); defineExpose({ - initSeek, performSeek, playPause, stop, toggleLoop, - length, + showPattern, + duration, loading, loop, playing, position, volume, + patternVisible, });