Android MediaMetadataRetriever fails to load metadata on old Samsung devices

时光毁灭记忆、已成空白 提交于 2019-12-11 07:26:45

问题


I'm facing a strange issue when using the android.media.MediaMetadataRetriever. It fails to extract the video width from video files on Samsung phones with Android version 4.0.4 and 4.1.2. The call metaRetriever.extractMetadata() seems to return either null or an empty string, as users of my app are reporting the VideoSetupException with error code ASVF_3.

It works on the Google emulators with said Android versions and all other Android versions and devices.

Any idea what might be causing this? It seems to me that there is a bug in the Android version distributed by Samsung.

Thanks a lot.

M.

    private void setVideoViewDimensionToMatchVideoMetadata(VideoView videoView, Uri uri) {
    String metadataVideoWidth;
    String metadataVideoHeight;
    try {
        final MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
        metaRetriever.setDataSource(getActivity(), uri);
        metadataVideoWidth = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
        metadataVideoHeight = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
        metaRetriever.release();
    } catch (NullPointerException | IllegalArgumentException ex) {
        throw new VideoSetupException(getActivity().getString(R.string.ASVF_2)
                + StringUtils.SPACE + ex.getLocalizedMessage(), ex);
    }
    if (StringUtils.isEmpty(metadataVideoWidth)) {
        throw new VideoSetupException(getActivity().getString(R.string.ASVF_3));
    }

来源:https://stackoverflow.com/questions/41557384/android-mediametadataretriever-fails-to-load-metadata-on-old-samsung-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!