Merge pull request #3254 from TheWidlarzGroup/feat/is-codec-supported-update
feat(android): update `isCodecSupported` to return enum
This commit is contained in:
commit
21de75eac6
5
API.md
5
API.md
@ -1684,8 +1684,9 @@ parameters:
|
|||||||
- **width**, **height**: resolution to query
|
- **width**, **height**: resolution to query
|
||||||
|
|
||||||
Possible results:
|
Possible results:
|
||||||
- **true** - codec supported
|
- **`hardware`** - codec is supported by hardware
|
||||||
- **false** - codec is not supported
|
- **`software`** - codec is supported by software only
|
||||||
|
- **`unsupported`** - codec is not supported
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```
|
```
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
## Next
|
## Next
|
||||||
- Windows: fix build error from over-specified SDK version [#3246](https://github.com/react-native-video/react-native-video/pull/3246)
|
- Windows: fix build error from over-specified SDK version [#3246](https://github.com/react-native-video/react-native-video/pull/3246)
|
||||||
- Windows: fix `onError` not being raised [#3247](https://github.com/react-native-video/react-native-video/pull/3247)
|
- Windows: fix `onError` not being raised [#3247](https://github.com/react-native-video/react-native-video/pull/3247)
|
||||||
|
- **BREAKING CHANGE**❗️Android: update isCodecSupported to return enum [#3254](https://github.com/react-native-video/react-native-video/pull/3254)
|
||||||
|
|
||||||
### Version 6.0.0-alpha.8
|
### Version 6.0.0-alpha.8
|
||||||
- All: Playing audio over earpiece [#2887](https://github.com/react-native-video/react-native-video/issues/2887)
|
- All: Playing audio over earpiece [#2887](https://github.com/react-native-video/react-native-video/issues/2887)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.brentvatne.react;
|
package com.brentvatne.react;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.media.MediaCodecInfo;
|
||||||
import android.media.MediaCodecList;
|
import android.media.MediaCodecList;
|
||||||
import android.media.MediaDrm;
|
import android.media.MediaDrm;
|
||||||
import android.media.MediaFormat;
|
import android.media.MediaFormat;
|
||||||
@ -79,18 +80,36 @@ public class VideoDecoderPropertiesModule extends ReactContextBaseJavaModule {
|
|||||||
@SuppressLint("ObsoleteSdkInt")
|
@SuppressLint("ObsoleteSdkInt")
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void isCodecSupported(String mimeType, int width, int height, Promise p) {
|
public void isCodecSupported(String mimeType, int width, int height, Promise p) {
|
||||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||||
p.resolve(false);
|
p.resolve("unsupported");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaCodecList mRegularCodecs = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
|
MediaCodecList mRegularCodecs = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
|
||||||
MediaFormat format = MediaFormat.createVideoFormat(mimeType, width, height);
|
MediaFormat format = MediaFormat.createVideoFormat(mimeType, width, height);
|
||||||
String codecName = mRegularCodecs.findDecoderForFormat(format);
|
String codecName = mRegularCodecs.findDecoderForFormat(format);
|
||||||
|
|
||||||
if (codecName == null) {
|
if (codecName == null) {
|
||||||
p.resolve(false);
|
p.resolve("unsupported");
|
||||||
} else {
|
return;
|
||||||
p.resolve(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback for android < 10
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||||
|
p.resolve("software");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isHardwareAccelerated = false;
|
||||||
|
|
||||||
|
for (MediaCodecInfo codecInfo : mRegularCodecs.getCodecInfos()) {
|
||||||
|
if (codecInfo.getName().equalsIgnoreCase(codecName)) {
|
||||||
|
isHardwareAccelerated = codecInfo.isHardwareAccelerated();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p.resolve(isHardwareAccelerated ? "software" : "hardware");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,25 +86,23 @@ class VideoPlayer extends Component {
|
|||||||
|
|
||||||
popupInfo = () => {
|
popupInfo = () => {
|
||||||
VideoDecoderProperties.getWidevineLevel().then((widevineLevel: number) => {
|
VideoDecoderProperties.getWidevineLevel().then((widevineLevel: number) => {
|
||||||
VideoDecoderProperties.isHEVCSupported().then((hevcSupported: boolean) => {
|
VideoDecoderProperties.isHEVCSupported().then((hevc: string) => {
|
||||||
VideoDecoderProperties.isCodecSupported('video/avc', 1920, 1080).then(
|
VideoDecoderProperties.isCodecSupported('video/avc', 1920, 1080).then(
|
||||||
(avcSupported: boolean) => {
|
(avc: string) => {
|
||||||
this.toast(
|
this.toast(
|
||||||
true,
|
true,
|
||||||
'Widevine level: ' +
|
'Widevine level: ' +
|
||||||
widevineLevel +
|
widevineLevel +
|
||||||
'\n hevc: ' +
|
'\n hevc: ' +
|
||||||
(hevcSupported ? '' : 'NOT') +
|
hevc +
|
||||||
'supported' +
|
|
||||||
'\n avc: ' +
|
'\n avc: ' +
|
||||||
(avcSupported ? '' : 'NOT') +
|
avc,
|
||||||
'supported',
|
);
|
||||||
)
|
|
||||||
},
|
},
|
||||||
)
|
);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
onLoad = (data: any) => {
|
onLoad = (data: any) => {
|
||||||
this.setState({ duration: data.duration, loading: false, });
|
this.setState({ duration: data.duration, loading: false, });
|
||||||
|
Loading…
Reference in New Issue
Block a user