Fix and improve VideoNativeComponent (canPlay/isWidewine supportd) for web

This commit is contained in:
Zoe Roux 2024-07-09 12:38:47 +07:00
parent e610a274d5
commit 3dabf5f16f
No known key found for this signature in database
2 changed files with 18 additions and 28 deletions

View File

@ -3,6 +3,7 @@
"version": "1.0.0", "version": "1.0.0",
"private": true, "private": true,
"scripts": { "scripts": {
"web": "expo run:web",
"android": "expo run:android", "android": "expo run:android",
"ios": "expo run:ios", "ios": "expo run:ios",
"windows": "react-native run-windows", "windows": "react-native run-windows",

View File

@ -1,25 +1,20 @@
/// <reference lib="dom" /> /// <reference lib="dom" />
import type {VideoDecoderPropertiesType} from './specs/VideoNativeComponent'; import type {VideoDecoderPropertiesType} from './specs/VideoNativeComponent';
class VideoDecoderProperties implements VideoDecoderPropertiesType { const canPlay = (codec: string): boolean => {
async getWidevineLevel() {
return 0;
}
static canPlay(codec: string): boolean {
// most chrome based browser (and safari I think) supports matroska but reports they do not. // most chrome based browser (and safari I think) supports matroska but reports they do not.
// for those browsers, only check the codecs and not the container. // for those browsers, only check the codecs and not the container.
if (navigator.userAgent.search('Firefox') === -1) { if (navigator.userAgent.search('Firefox') === -1) {
codec = codec.replace('video/x-matroska', 'video/mp4'); codec = codec.replace('video/x-matroska', 'video/mp4');
} }
// Find any video element that we could use to check, or create one that will return !!MediaSource.isTypeSupported(codec);
// instantly be garbage collected };
const videos = document.getElementsByTagName('video');
const video = videos.item(0) ?? document.createElement('video');
return !!video.canPlayType(codec); export const VideoDecoderProperties = {
} async getWidevineLevel() {
return 0;
},
async isCodecSupported( async isCodecSupported(
mimeType: string, mimeType: string,
@ -27,19 +22,13 @@ class VideoDecoderProperties implements VideoDecoderPropertiesType {
_height: number, _height: number,
): Promise<'unsupported' | 'hardware' | 'software'> { ): Promise<'unsupported' | 'hardware' | 'software'> {
// TODO: Figure out if we can get hardware support information // TODO: Figure out if we can get hardware support information
return VideoDecoderProperties.canPlay(mimeType) return canPlay(mimeType) ? 'software' : 'unsupported';
? 'software' },
: 'unsupported';
}
async isHEVCSupported(): Promise<'unsupported' | 'hardware' | 'software'> { async isHEVCSupported(): Promise<'unsupported' | 'hardware' | 'software'> {
// Just a dummy vidoe mime type codec with HEVC to check. // Just a dummy vidoe mime type codec with HEVC to check.
return VideoDecoderProperties.canPlay( return canPlay('video/x-matroska; codecs="hvc1.1.4.L96.BO"')
'video/x-matroska; codecs="hvc1.1.4.L96.BO"',
)
? 'software' ? 'software'
: 'unsupported'; : 'unsupported';
} },
} } satisfies VideoDecoderPropertiesType;
export default VideoDecoderProperties;