2017-07-01 28 views
0

我必須選擇在選配意圖視頻或圖像這樣得到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

使用此來獲得您的所有要求。

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() 
} 

希望這有幫助,並讓我知道是否有任何問題出現。

+0

它不會得到這個錯誤 'java.lang.RuntimeException:傳遞結果失敗ResultInfo {who = null,request = 1,result = -1,data = Intent {dat = content:// media/external/images/media/57}} to activity {com.ts.tkllm/com.ts.tkllm.Chat}:java.lang.RuntimeException:setDataSource failed:status = 0x80000000' –

+0

您是否提供了正確的數據文件路徑,通過onActivityResult()? –

+0

感謝您爲視頻 工作,我用drewnoakes:metadata-extractor:2.10.1爲圖像 –

相關問題