2024-01-15 10:17:01 +01:00
|
|
|
<!--
|
2024-02-13 16:59:27 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2024-01-15 10:17:01 +01:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div
|
2024-03-30 08:02:03 +01:00
|
|
|
ref="playerEl"
|
|
|
|
v-hotkey="keymap"
|
|
|
|
tabindex="0"
|
2024-01-15 10:17:01 +01:00
|
|
|
:class="[
|
|
|
|
$style.audioContainer,
|
|
|
|
(audio.isSensitive && defaultStore.state.highlightSensitiveMedia) && $style.sensitive,
|
|
|
|
]"
|
|
|
|
@contextmenu.stop
|
2024-03-30 08:02:03 +01:00
|
|
|
@keydown.stop
|
2024-01-15 10:17:01 +01:00
|
|
|
>
|
|
|
|
<button v-if="hide" :class="$style.hidden" @click="hide = false">
|
|
|
|
<div :class="$style.hiddenTextWrapper">
|
2024-06-21 16:21:11 +02:00
|
|
|
<b v-if="audio.isSensitive" style="display: block;"><i class="ti ti-eye-exclamation"></i> {{ i18n.ts.sensitive }}{{ defaultStore.state.dataSaver.media ? ` (${i18n.ts.audio}${audio.size ? ' ' + bytes(audio.size) : ''})` : '' }}</b>
|
2024-06-21 19:12:01 +02:00
|
|
|
<b v-else style="display: block;"><i class="ti ti-music"></i> {{ defaultStore.state.dataSaver.media && audio.size ? bytes(audio.size) : i18n.ts.audio }}</b>
|
2024-01-15 10:17:01 +01:00
|
|
|
<span style="display: block;">{{ i18n.ts.clickToShow }}</span>
|
|
|
|
</div>
|
|
|
|
</button>
|
2024-03-30 08:02:03 +01:00
|
|
|
|
|
|
|
<div v-else-if="defaultStore.reactiveState.useNativeUIForVideoAudioPlayer.value" :class="$style.nativeAudioContainer">
|
|
|
|
<audio
|
|
|
|
ref="audioEl"
|
|
|
|
preload="metadata"
|
|
|
|
controls
|
|
|
|
:class="$style.nativeAudio"
|
|
|
|
@keydown.prevent
|
|
|
|
>
|
|
|
|
<source :src="audio.url">
|
|
|
|
</audio>
|
|
|
|
</div>
|
|
|
|
|
2024-01-15 10:17:01 +01:00
|
|
|
<div v-else :class="$style.audioControls">
|
|
|
|
<audio
|
|
|
|
ref="audioEl"
|
|
|
|
preload="metadata"
|
|
|
|
>
|
|
|
|
<source :src="audio.url">
|
|
|
|
</audio>
|
|
|
|
<div :class="[$style.controlsChild, $style.controlsLeft]">
|
|
|
|
<button class="_button" :class="$style.controlButton" @click="togglePlayPause">
|
2024-06-22 12:26:18 +02:00
|
|
|
<i v-if="isPlaying" class="ti ti-player-pause-filled"></i>
|
|
|
|
<i v-else class="ti ti-player-play-filled"></i>
|
2024-01-15 10:17:01 +01:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div :class="[$style.controlsChild, $style.controlsRight]">
|
2024-01-24 17:26:28 +01:00
|
|
|
<a class="_button" :class="$style.controlButton" :href="audio.url" :download="audio.name" target="_blank">
|
|
|
|
<i class="ph-download ph-bold ph-lg"></i>
|
|
|
|
</a>
|
2024-01-15 10:17:01 +01:00
|
|
|
<button class="_button" :class="$style.controlButton" @click="showMenu">
|
2024-06-21 15:42:59 +02:00
|
|
|
<i class="ti ti-settings"></i>
|
2024-01-15 10:17:01 +01:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div :class="[$style.controlsChild, $style.controlsTime]">{{ hms(elapsedTimeMs) }}</div>
|
|
|
|
<div :class="[$style.controlsChild, $style.controlsVolume]">
|
|
|
|
<button class="_button" :class="$style.controlButton" @click="toggleMute">
|
2024-06-22 12:26:18 +02:00
|
|
|
<i v-if="volume === 0" class="ti ti-volume-3"></i>
|
|
|
|
<i v-else class="ti ti-volume"></i>
|
2024-01-15 10:17:01 +01:00
|
|
|
</button>
|
|
|
|
<MkMediaRange
|
|
|
|
v-model="volume"
|
|
|
|
:class="$style.volumeSeekbar"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<MkMediaRange
|
|
|
|
v-model="rangePercent"
|
|
|
|
:class="$style.seekbarRoot"
|
|
|
|
:buffer="bufferedDataRatio"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { shallowRef, watch, computed, ref, onDeactivated, onActivated, onMounted } from 'vue';
|
|
|
|
import * as Misskey from 'misskey-js';
|
|
|
|
import type { MenuItem } from '@/types/menu.js';
|
|
|
|
import { defaultStore } from '@/store.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import * as os from '@/os.js';
|
|
|
|
import bytes from '@/filters/bytes.js';
|
|
|
|
import { hms } from '@/filters/hms.js';
|
|
|
|
import MkMediaRange from '@/components/MkMediaRange.vue';
|
2024-03-05 10:06:57 +01:00
|
|
|
import { $i, iAmModerator } from '@/account.js';
|
2024-01-15 10:17:01 +01:00
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
audio: Misskey.entities.DriveFile;
|
|
|
|
}>();
|
|
|
|
|
2024-03-30 08:02:03 +01:00
|
|
|
const keymap = {
|
|
|
|
'up': () => {
|
|
|
|
if (hasFocus() && audioEl.value) {
|
|
|
|
volume.value = Math.min(volume.value + 0.1, 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'down': () => {
|
|
|
|
if (hasFocus() && audioEl.value) {
|
|
|
|
volume.value = Math.max(volume.value - 0.1, 0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'left': () => {
|
|
|
|
if (hasFocus() && audioEl.value) {
|
|
|
|
audioEl.value.currentTime = Math.max(audioEl.value.currentTime - 5, 0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'right': () => {
|
|
|
|
if (hasFocus() && audioEl.value) {
|
|
|
|
audioEl.value.currentTime = Math.min(audioEl.value.currentTime + 5, audioEl.value.duration);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'space': () => {
|
|
|
|
if (hasFocus()) {
|
|
|
|
togglePlayPause();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// PlayerElもしくはその子要素にフォーカスがあるかどうか
|
|
|
|
function hasFocus() {
|
|
|
|
if (!playerEl.value) return false;
|
|
|
|
return playerEl.value === document.activeElement || playerEl.value.contains(document.activeElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
const playerEl = shallowRef<HTMLDivElement>();
|
2024-01-15 10:17:01 +01:00
|
|
|
const audioEl = shallowRef<HTMLAudioElement>();
|
|
|
|
|
|
|
|
// eslint-disable-next-line vue/no-setup-props-destructure
|
|
|
|
const hide = ref((defaultStore.state.nsfw === 'force' || defaultStore.state.dataSaver.media) ? true : (props.audio.isSensitive && defaultStore.state.nsfw !== 'ignore'));
|
|
|
|
|
|
|
|
// Menu
|
|
|
|
const menuShowing = ref(false);
|
|
|
|
|
|
|
|
function showMenu(ev: MouseEvent) {
|
|
|
|
let menu: MenuItem[] = [];
|
|
|
|
|
|
|
|
menu = [
|
|
|
|
// TODO: 再生キューに追加
|
2024-03-30 08:02:03 +01:00
|
|
|
{
|
|
|
|
type: 'switch',
|
|
|
|
text: i18n.ts._mediaControls.loop,
|
2024-04-12 17:12:00 +02:00
|
|
|
icon: 'ph ph-repeat',
|
2024-03-30 08:02:03 +01:00
|
|
|
ref: loop,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'radio',
|
|
|
|
text: i18n.ts._mediaControls.playbackRate,
|
2024-04-12 17:12:00 +02:00
|
|
|
icon: 'ph ph-gauge',
|
2024-03-30 08:02:03 +01:00
|
|
|
ref: speed,
|
|
|
|
options: {
|
|
|
|
'0.25x': 0.25,
|
|
|
|
'0.5x': 0.5,
|
|
|
|
'0.75x': 0.75,
|
|
|
|
'1.0x': 1,
|
|
|
|
'1.25x': 1.25,
|
|
|
|
'1.5x': 1.5,
|
|
|
|
'2.0x': 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'divider',
|
|
|
|
},
|
2024-01-15 10:17:01 +01:00
|
|
|
{
|
|
|
|
text: i18n.ts.hide,
|
2024-06-21 16:15:04 +02:00
|
|
|
icon: 'ti ti-eye-off',
|
2024-01-15 10:17:01 +01:00
|
|
|
action: () => {
|
|
|
|
hide.value = true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
if (iAmModerator) {
|
|
|
|
menu.push({
|
|
|
|
text: props.audio.isSensitive ? i18n.ts.unmarkAsSensitive : i18n.ts.markAsSensitive,
|
2024-06-21 16:21:11 +02:00
|
|
|
icon: props.audio.isSensitive ? 'ti ti-eye' : 'ti ti-eye-exclamation',
|
2024-01-15 10:17:01 +01:00
|
|
|
danger: true,
|
|
|
|
action: () => toggleSensitive(props.audio),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-03-05 10:06:57 +01:00
|
|
|
if ($i?.id === props.audio.userId) {
|
|
|
|
menu.push({
|
|
|
|
type: 'divider',
|
|
|
|
}, {
|
|
|
|
type: 'link' as const,
|
|
|
|
text: i18n.ts._fileViewer.title,
|
2024-06-21 17:27:36 +02:00
|
|
|
icon: 'ti ti-info-circle',
|
2024-03-05 10:06:57 +01:00
|
|
|
to: `/my/drive/file/${props.audio.id}`,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-01-15 10:17:01 +01:00
|
|
|
menuShowing.value = true;
|
|
|
|
os.popupMenu(menu, ev.currentTarget ?? ev.target, {
|
|
|
|
align: 'right',
|
|
|
|
onClosing: () => {
|
|
|
|
menuShowing.value = false;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleSensitive(file: Misskey.entities.DriveFile) {
|
|
|
|
os.apiWithDialog('drive/files/update', {
|
|
|
|
fileId: file.id,
|
|
|
|
isSensitive: !file.isSensitive,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// MediaControl: Common State
|
|
|
|
const oncePlayed = ref(false);
|
|
|
|
const isReady = ref(false);
|
|
|
|
const isPlaying = ref(false);
|
|
|
|
const isActuallyPlaying = ref(false);
|
|
|
|
const elapsedTimeMs = ref(0);
|
|
|
|
const durationMs = ref(0);
|
|
|
|
const rangePercent = computed({
|
|
|
|
get: () => {
|
|
|
|
return (elapsedTimeMs.value / durationMs.value) || 0;
|
|
|
|
},
|
|
|
|
set: (to) => {
|
|
|
|
if (!audioEl.value) return;
|
|
|
|
audioEl.value.currentTime = to * durationMs.value / 1000;
|
|
|
|
},
|
|
|
|
});
|
2024-01-18 06:45:11 +01:00
|
|
|
const volume = ref(.25);
|
2024-03-30 08:02:03 +01:00
|
|
|
const speed = ref(1);
|
|
|
|
const loop = ref(false); // TODO: ドライブファイルのフラグに置き換える
|
2024-01-15 10:17:01 +01:00
|
|
|
const bufferedEnd = ref(0);
|
|
|
|
const bufferedDataRatio = computed(() => {
|
|
|
|
if (!audioEl.value) return 0;
|
|
|
|
return bufferedEnd.value / audioEl.value.duration;
|
|
|
|
});
|
|
|
|
|
|
|
|
// MediaControl Events
|
|
|
|
function togglePlayPause() {
|
|
|
|
if (!isReady.value || !audioEl.value) return;
|
|
|
|
|
|
|
|
if (isPlaying.value) {
|
|
|
|
audioEl.value.pause();
|
|
|
|
isPlaying.value = false;
|
|
|
|
} else {
|
|
|
|
audioEl.value.play();
|
|
|
|
isPlaying.value = true;
|
|
|
|
oncePlayed.value = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleMute() {
|
|
|
|
if (volume.value === 0) {
|
2024-01-18 06:45:11 +01:00
|
|
|
volume.value = .25;
|
2024-01-15 10:17:01 +01:00
|
|
|
} else {
|
|
|
|
volume.value = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let onceInit = false;
|
2024-03-30 08:02:03 +01:00
|
|
|
let mediaTickFrameId: number | null = null;
|
2024-01-15 10:17:01 +01:00
|
|
|
let stopAudioElWatch: () => void;
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
if (onceInit) return;
|
|
|
|
onceInit = true;
|
|
|
|
|
|
|
|
stopAudioElWatch = watch(audioEl, () => {
|
|
|
|
if (audioEl.value) {
|
|
|
|
isReady.value = true;
|
|
|
|
|
|
|
|
function updateMediaTick() {
|
|
|
|
if (audioEl.value) {
|
|
|
|
try {
|
|
|
|
bufferedEnd.value = audioEl.value.buffered.end(0);
|
|
|
|
} catch (err) {
|
|
|
|
bufferedEnd.value = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
elapsedTimeMs.value = audioEl.value.currentTime * 1000;
|
2024-03-30 08:02:03 +01:00
|
|
|
|
|
|
|
if (audioEl.value.loop !== loop.value) {
|
|
|
|
loop.value = audioEl.value.loop;
|
|
|
|
}
|
2024-01-15 10:17:01 +01:00
|
|
|
}
|
2024-03-30 08:02:03 +01:00
|
|
|
mediaTickFrameId = window.requestAnimationFrame(updateMediaTick);
|
2024-01-15 10:17:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
updateMediaTick();
|
|
|
|
|
|
|
|
audioEl.value.addEventListener('play', () => {
|
|
|
|
isActuallyPlaying.value = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
audioEl.value.addEventListener('pause', () => {
|
|
|
|
isActuallyPlaying.value = false;
|
|
|
|
isPlaying.value = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
audioEl.value.addEventListener('ended', () => {
|
|
|
|
oncePlayed.value = false;
|
|
|
|
isActuallyPlaying.value = false;
|
|
|
|
isPlaying.value = false;
|
|
|
|
});
|
2024-01-18 06:45:11 +01:00
|
|
|
|
2024-01-15 10:17:01 +01:00
|
|
|
durationMs.value = audioEl.value.duration * 1000;
|
|
|
|
audioEl.value.addEventListener('durationchange', () => {
|
|
|
|
if (audioEl.value) {
|
|
|
|
durationMs.value = audioEl.value.duration * 1000;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
audioEl.value.volume = volume.value;
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
immediate: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
watch(volume, (to) => {
|
|
|
|
if (audioEl.value) audioEl.value.volume = to;
|
|
|
|
});
|
|
|
|
|
2024-03-30 08:02:03 +01:00
|
|
|
watch(speed, (to) => {
|
|
|
|
if (audioEl.value) audioEl.value.playbackRate = to;
|
|
|
|
});
|
|
|
|
|
|
|
|
watch(loop, (to) => {
|
|
|
|
if (audioEl.value) audioEl.value.loop = to;
|
|
|
|
});
|
|
|
|
|
2024-01-15 10:17:01 +01:00
|
|
|
onMounted(() => {
|
|
|
|
init();
|
|
|
|
});
|
|
|
|
|
|
|
|
onActivated(() => {
|
|
|
|
init();
|
|
|
|
});
|
|
|
|
|
|
|
|
onDeactivated(() => {
|
|
|
|
isReady.value = false;
|
|
|
|
isPlaying.value = false;
|
|
|
|
isActuallyPlaying.value = false;
|
|
|
|
elapsedTimeMs.value = 0;
|
|
|
|
durationMs.value = 0;
|
|
|
|
bufferedEnd.value = 0;
|
|
|
|
hide.value = (defaultStore.state.nsfw === 'force' || defaultStore.state.dataSaver.media) ? true : (props.audio.isSensitive && defaultStore.state.nsfw !== 'ignore');
|
|
|
|
stopAudioElWatch();
|
|
|
|
onceInit = false;
|
2024-03-30 08:02:03 +01:00
|
|
|
if (mediaTickFrameId) {
|
|
|
|
window.cancelAnimationFrame(mediaTickFrameId);
|
|
|
|
mediaTickFrameId = null;
|
|
|
|
}
|
2024-01-15 10:17:01 +01:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.audioContainer {
|
|
|
|
container-type: inline-size;
|
|
|
|
position: relative;
|
|
|
|
border: .5px solid var(--divider);
|
|
|
|
border-radius: var(--radius);
|
|
|
|
overflow: clip;
|
2024-03-30 08:02:03 +01:00
|
|
|
|
|
|
|
&:focus {
|
|
|
|
outline: none;
|
|
|
|
}
|
2024-01-15 10:17:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
.sensitive {
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
&::after {
|
|
|
|
content: "";
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
pointer-events: none;
|
|
|
|
border-radius: inherit;
|
|
|
|
box-shadow: inset 0 0 0 4px var(--warn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.hidden {
|
|
|
|
width: 100%;
|
2024-01-27 08:33:30 +01:00
|
|
|
background: #000;
|
2024-01-15 10:17:01 +01:00
|
|
|
border: none;
|
|
|
|
outline: none;
|
|
|
|
font: inherit;
|
|
|
|
color: inherit;
|
|
|
|
cursor: pointer;
|
|
|
|
padding: 12px 0;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.hiddenTextWrapper {
|
|
|
|
text-align: center;
|
|
|
|
font-size: 0.8em;
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
|
|
|
|
.audioControls {
|
|
|
|
display: grid;
|
|
|
|
grid-template-areas:
|
|
|
|
"left time . volume right"
|
|
|
|
"seekbar seekbar seekbar seekbar seekbar";
|
|
|
|
grid-template-columns: auto auto 1fr auto auto;
|
|
|
|
align-items: center;
|
|
|
|
gap: 4px 8px;
|
|
|
|
padding: 10px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.controlsChild {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
gap: 4px;
|
|
|
|
|
|
|
|
.controlButton {
|
|
|
|
padding: 6px;
|
|
|
|
border-radius: calc(var(--radius) / 2);
|
|
|
|
font-size: 1.05rem;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
color: var(--accent);
|
|
|
|
background-color: var(--accentedBg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.controlsLeft {
|
|
|
|
grid-area: left;
|
|
|
|
}
|
|
|
|
|
|
|
|
.controlsRight {
|
|
|
|
grid-area: right;
|
|
|
|
}
|
|
|
|
|
|
|
|
.controlsTime {
|
|
|
|
grid-area: time;
|
|
|
|
font-size: .9rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.controlsVolume {
|
|
|
|
grid-area: volume;
|
|
|
|
|
|
|
|
.volumeSeekbar {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.seekbarRoot {
|
|
|
|
grid-area: seekbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
@container (min-width: 500px) {
|
|
|
|
.audioControls {
|
|
|
|
grid-template-areas: "left seekbar time volume right";
|
|
|
|
grid-template-columns: auto 1fr auto auto auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.controlsVolume {
|
|
|
|
.volumeSeekbar {
|
|
|
|
max-width: 90px;
|
|
|
|
display: block;
|
|
|
|
flex-grow: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-03-30 08:02:03 +01:00
|
|
|
|
|
|
|
.nativeAudioContainer {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
padding: 6px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.nativeAudio {
|
|
|
|
display: block;
|
|
|
|
width: 100%;
|
|
|
|
}
|
2024-01-15 10:17:01 +01:00
|
|
|
</style>
|