Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): update isCodecSupported to return enum #3254

Merged
merged 5 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1684,8 +1684,9 @@ parameters:
- **width**, **height**: resolution to query

Possible results:
- **true** - codec supported
- **false** - codec is not supported
- **`hardware`** - codec is supported by hardware
- **`software`** - codec is supported by software only
- **`unsupported`** - codec is not supported

Example:
```
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Next
- 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)
- **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
- All: Playing audio over earpiece [#2887](https://github.com/react-native-video/react-native-video/issues/2887)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.brentvatne.react;

import android.annotation.SuppressLint;
import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.media.MediaDrm;
import android.media.MediaFormat;
Expand Down Expand Up @@ -79,18 +80,36 @@ public void getWidevineLevel(Promise p) {
@SuppressLint("ObsoleteSdkInt")
@ReactMethod
public void isCodecSupported(String mimeType, int width, int height, Promise p) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
p.resolve(false);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
p.resolve("unsupported");
return;
}

MediaCodecList mRegularCodecs = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
MediaFormat format = MediaFormat.createVideoFormat(mimeType, width, height);
String codecName = mRegularCodecs.findDecoderForFormat(format);

if (codecName == null) {
p.resolve(false);
} else {
p.resolve(true);
p.resolve("unsupported");
return;
}

// 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");
}


Expand Down
20 changes: 9 additions & 11 deletions examples/basic/src/VideoPlayer.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,23 @@ class VideoPlayer extends Component {

popupInfo = () => {
VideoDecoderProperties.getWidevineLevel().then((widevineLevel: number) => {
VideoDecoderProperties.isHEVCSupported().then((hevcSupported: boolean) => {
VideoDecoderProperties.isHEVCSupported().then((hevc: string) => {
VideoDecoderProperties.isCodecSupported('video/avc', 1920, 1080).then(
(avcSupported: boolean) => {
(avc: string) => {
this.toast(
true,
'Widevine level: ' +
widevineLevel +
'\n hevc: ' +
(hevcSupported ? '' : 'NOT') +
'supported' +
hevc +
'\n avc: ' +
(avcSupported ? '' : 'NOT') +
'supported',
)
avc,
);
},
)
})
})
}
);
});
});
};

onLoad = (data: any) => {
this.setState({ duration: data.duration, loading: false, });
Expand Down