获取媒体元数据onActivityResult

时间:2017-07-01 04:46:04

标签: android metadata onactivityresult

我必须选择像这样的选择器意图上的视频或图像

Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
                getIntent.setType("image/* video/*");

                Intent pickIntent = new Intent(Intent.ACTION_PICK);
                pickIntent.setType("image/* video/*");

Intent chooserIntent = Intent.createChooser(getIntent, "Select Media");
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});

                startActivityForResult(chooserIntent, 1);

然后我想获取onActivityResult()中所选文件的元数据 喜欢视频的高度和宽度和长度以及大小

1 个答案:

答案 0 :(得分:1)

使用它来满足您的所有要求。

MediaMetadataRetriever ret = new  MediaMetadataRetriever();
Bitmap bmp = null;      

try 
{
    ret.setDataSource("<<--Your retrieved data file-->>");
    bmp = ret.getFrameAtTime();
    videoHeight=bmp.getHeight();
    videoWidth=bmp.getWidth();
    videoSize = bmp.getAllocationByteCount()
}

希望这会有所帮助,如果出现任何问题,请告诉我。