2016-12-10 8 views
0

が動作していない:取得ストレージからの映像情報は、私はこの単純なコードを使用して、ビデオの幅とサイズを取得しようとしている

String[] filePathColumn = {MediaStore.Video.VideoColumns.DATA, 
         MediaStore.Video.VideoColumns.WIDTH, 
         MediaStore.Video.VideoColumns.HEIGHT}; 
cursor = mContext.getContentResolver().query(mVideoUri, filePathColumn, null, null, null); 
if (cursor != null && cursor.moveToFirst()) { 
     mVideoDecodableString = cursor.getString(cursor.getColumnIndex(filePathColumn[0])); 
     mVideoWidth = cursor.getInt(cursor.getColumnIndex(filePathColumn[1])); 
     mVideoHeight = cursor.getInt(cursor.getColumnIndex(filePathColumn[2])); 
} 

生憎私はいつも私のギャラリー内のすべてのビデオファイルのための0幅と高さを得るが、ビデオデータを取得する。

私は何か間違っているのですか、それともAndroidではできませんか?

答えて

1

MediaMetadataRetrieverを使用して、ビデオファイルの高さを&にすることができます。

METADATA_KEY_VIDEO_HEIGHTMETADATA_KEY_VIDEO_WIDTHという定数を使用してextractMetadata()メソッドを使用する必要があります。

MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever(); 
metaRetriever.setDataSource(/* file path goes here. eg."/path/to/video.mp4" */); 
String height = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); 
String width = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH); 

注:MediaMetadataRetrieverAPIレベル10以上を必要とします。

編集:

私はわからないけど、私はあなたがたとえば以下のようなビデオファイル形式ContentResolverの解像度(高さ×幅)を取得するためにRESOLUTION列を使用する必要があると思います。

String[] projection = new String[] {MediaStore.Video.VideoColumns.RESOLUTION}; 
Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); 
if (cursor.moveToFirst()) { 
    String resolution = cursor.getString(0); 
    if(!StringUtils.isEmpty(resolution)) { 
     int index = resolution.indexOf('x'); 
     width = Integer.parseInt(resolution.substring(0, index)); 
     height = Integer.parseInt(resolution.substring(index + 1)); 
} 
+0

これは完全に動作します、私の質問はなぜ問題のコードが機能しないのですか?あなたが説明できるなら、私はあなたの答えを受け入れます。 – ThirdMartian

+0

@ThirdMartianは、ビデオ解像度フォーム 'ContentResolver'を取得した私の編集された答えをチェックします。 –

関連する問題