chore(frontend/MkMediaVideo): loop and autoplay silent videos (#12392)

This commit is contained in:
Acid Chicken (硫酸鶏)
2023-11-26 16:15:24 +09:00
committed by GitHub
parent c9503da8f8
commit d60f645d1d
2 changed files with 16 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
export default async function hasAudio(media: HTMLMediaElement) {
const cloned = media.cloneNode() as HTMLMediaElement;
cloned.muted = (cloned as typeof cloned & Partial<HTMLVideoElement>).playsInline = true;
cloned.play();
await new Promise((resolve) => cloned.addEventListener('playing', resolve));
const result = !!(cloned as any).audioTracks?.length || (cloned as any).mozHasAudio || !!(cloned as any).webkitAudioDecodedByteCount;
cloned.remove();
return result;
}