mirror of
https://github.com/paricafe/misskey.git
synced 2024-12-12 03:06:44 -06:00
10 lines
476 B
TypeScript
10 lines
476 B
TypeScript
|
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;
|
||
|
}
|