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);
// ...
}
}
});
isHardwareAccelerated 为 true 表示视频正在使用硬件加速。
总结: ExoPlayer 会自动利用设备硬件加速来提升视频播放性能,您只需关注视频播放即可。
原文地址: https://www.cveoy.top/t/topic/njEA 著作权归作者所有。请勿转载和采集!