-
Notifications
You must be signed in to change notification settings - Fork 2
/
media.js
49 lines (43 loc) · 1.42 KB
/
media.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const useMediaCapabilities = mediaConfig => {
let initialMediaCapabilities;
// 检查浏览器是否支持 navigator.mediaCapabilities
if (typeof navigator !== "undefined" && "mediaCapabilities" in navigator) {
unsupported = false;
const result = navigator.mediaCapabilities.decodingInfo(mediaConfig);
if (result.support === true) {
initialMediaCapabilities = {
support: result,
smooth: result.smooth,
powerEfficient: result.powerEfficient
};
} else {
initialMediaCapabilities = {
unsupported: true
};
}
} else if (typeof window !== 'undefined' && "MediaSource" in window) {
initialMediaCapabilities = {
support: MediaSource.isTypeSupported(
mediaConfig.audio.contentType || mediaConfig.video.contentType
)
};
} else {
initialMediaCapabilities = {
unsupported: true
};
}
return {
...initialMediaCapabilities
};
};
const useMediaDevices = () => {
// 检查浏览器是否支持 navigator.mediaDevices
if (typeof navigator !== "undefined" && "mediaDevices" in navigator) {
return {
mediaDevices = navigator.mediaDevices
};
} else {
return { unsupported: true };
}
};
export { useMediaCapabilities, useMediaDevices };