exoplayer 如何判断视频是否支持硬件加速 或者如何自动使用硬件加速
ExoPlayer会自动使用设备硬件加速来播放视频,如果设备支持硬件加速。可以通过以下方法判断是否使用了硬件加速:
- 调用ExoPlayer的getVideoFormat方法,获取视频格式信息,其中包含了是否使用了硬件加速的信息。
Format videoFormat = exoPlayer.getVideoFormat();
if (videoFormat != null) {
boolean isHardwareAccelerated = videoFormat.getFeatureEnabled(Format.FEATURE_SECURE_CRYPTO);
// ...
}
- 监听ExoPlayer的OnVideoSizeChangedListener事件,当视频大小改变时,可以获取到视频格式信息。
exoPlayer.addVideoListener(new VideoListener() {
@Override
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
Format videoFormat = exoPlayer.getVideoFormat();
if (videoFormat != null) {
boolean isHardwareAccelerated = videoFormat.getFeatureEnabled(Format.FEATURE_SECURE_CRYPTO);
// ...
}
}
});
总的来说,ExoPlayer会自动使用设备硬件加速来播放视频,如果设备支持硬件加速。无需手动开启或关闭硬件加速。
原文地址: https://www.cveoy.top/t/topic/bW3W 著作权归作者所有。请勿转载和采集!