1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2025-01-02 16:37:39 +01:00
smov/src/utils/detectFeatures.ts
mrjvs c0fc201d74 show settings on playback error +
make hls play with hlsjs if possible + latest version of provider package

Co-authored-by: Jip Frijlink <JipFr@users.noreply.github.com>
2023-12-04 21:55:43 +01:00

54 lines
1.5 KiB
TypeScript

import fscreen from "fscreen";
import Hls from "hls.js";
export const isSafari = /^((?!chrome|android).)*safari/i.test(
navigator.userAgent
);
let cachedVolumeResult: boolean | null = null;
export async function canChangeVolume(): Promise<boolean> {
if (cachedVolumeResult === null) {
const timeoutPromise = new Promise<false>((resolve) => {
setTimeout(() => resolve(false), 1e3);
});
const promise = new Promise<true>((resolve) => {
const video = document.createElement("video");
const handler = () => {
video.removeEventListener("volumechange", handler);
resolve(true);
};
video.addEventListener("volumechange", handler);
video.volume = 0.5;
});
cachedVolumeResult = await Promise.race([promise, timeoutPromise]);
}
return cachedVolumeResult;
}
export function canFullscreenAnyElement(): boolean {
return fscreen.fullscreenEnabled;
}
export function canWebkitFullscreen(): boolean {
return canFullscreenAnyElement() || isSafari;
}
export function canFullscreen(): boolean {
return canFullscreenAnyElement() || canWebkitFullscreen();
}
export function canPictureInPicture(): boolean {
return "pictureInPictureEnabled" in document;
}
export function canWebkitPictureInPicture(): boolean {
return "webkitSupportsPresentationMode" in document.createElement("video");
}
export function canPlayHlsNatively(video: HTMLVideoElement): boolean {
if (Hls.isSupported()) return false; // no need to play natively
return !!video.canPlayType("application/vnd.apple.mpegurl");
}