2012-08-24 2 views
0

내가 SDCARD에 저장된 사용자의 동영상에 대한 정보를 검색하기 위해 노력하고있어, 나는이 방법했습니다 :미디어 스토어 MediaStore는 나에게 동영상 파일의 크기, 해상도, 시간 및 날짜를 ​​제공하지 않습니다

protected void addVideo() { 
    cursor = cr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, 
      mediaColumns, null, null, null); 

    if (cursor.moveToFirst()) { 

     int i = 1; 



     do { 

      VideoItem newVVI = new VideoItem(); 
      int id = cursor.getInt(cursor 
        .getColumnIndex(MediaStore.Video.Media._ID)); 
      newVVI.idthumb = cursor.getString(cursor 
        .getColumnIndex(MediaStore.Video.Thumbnails._ID)); 
      Cursor thumbCursor = cr.query(
        MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, 
        thumbColumns, MediaStore.Video.Thumbnails.VIDEO_ID 
          + "=" + id, null, null); 
      if (thumbCursor.moveToFirst()) { 
       newVVI.thumbPath = thumbCursor.getString(thumbCursor 
         .getColumnIndex(MediaStore.Video.Thumbnails.DATA)); 

      } 
      newVVI.filePath = cursor.getString(cursor 
        .getColumnIndexOrThrow(MediaStore.Video.Media.DATA)); 
      newVVI.title = cursor.getString(cursor 
        .getColumnIndexOrThrow(MediaStore.Video.Media.TITLE)); 
      try { 
       newVVI.date = cursor.getString(cursor 
         .getColumnIndexOrThrow(MediaStore.Video.Media.DATE_TAKEN)); 
      } catch (IllegalArgumentException e) { 
       // TODO Auto-generated catch block 
       newVVI.date = "0"; 
      } 
      try { 
       newVVI.duration = cursor.getString(cursor 
         .getColumnIndexOrThrow(MediaStore.Video.Media.DURATION)); 
      } catch (IllegalArgumentException e) { 
       // TODO Auto-generated catch block 
       newVVI.duration = "0"; 
      } 
      try { 
       newVVI.size = cursor.getString(cursor 
         .getColumnIndexOrThrow(MediaStore.Video.Media.SIZE)); 
      } catch (IllegalArgumentException e) { 
       // TODO Auto-generated catch block 
       newVVI.size = "0"; 
      } 
      try { 
       newVVI.resolution = cursor.getString(cursor 
         .getColumnIndexOrThrow(MediaStore.Video.Media.RESOLUTION)); 
      } catch (IllegalArgumentException e) { 
       // TODO Auto-generated catch block 
       newVVI.resolution = "0"; 
      } 

      newVVI.mimeType = cursor 
        .getString(cursor 
          .getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE)); 

      newVVI.id = Integer.toString(i); 
      ITEMS.add(newVVI); 
      ITEM_MAP.put(newVVI.id, newVVI); 
      i++; 


     } while (cursor.moveToNext()); 

     cursor.close(); 


    } else { 
     Log.d("TEST", ": else); 
    } 



} 

문제를 MediaStore.Video.Media.DATE, MediaStore.Video.Media.DURATION, MediaStore.Video.Media.SIZE 및 MediaStore.Video.Media.RESOLUTION에 대해서는 항상 "0"이됩니다. 왜냐하면 이러한 것들은 항상 IllegalArgumentException을 잡았 기 때문입니다.

왜?

답변

0

기본값은 0이므로 다른 값으로 설정되지 않았기 때문에 값은 0입니다. 비디오를 sdcard에 복사 할 때 MediaStore가이 값을 자동으로 계산하지 않습니다.

MediaPlayer을 사용하여 비디오를로드 한 다음 getDuration을 호출 해 볼 수 있습니다.

0

이 코드는 하나의 특수 오디오에서 정보를 반환합니다.하지만 실제로 작동했습니다. 모든 오디오 또는 비디오를 얻으려는 성명 질문에 대한 내 질문에 따라 변경할 수 있습니다. 내 응답에서 Mediastore.Video로 MediaStore.audio를 변경해야합니다. get your info from files by mediastore

:

String name=""; 
String duration=""; 
String path=""; 
Log.d("Loading file: " + filepath,""); 

     // This returns us content://media/external/videos/media (or something like that) 
     // I pass in "external" because that's the MediaStore's name for the external 
     // storage on my device (the other possibility is "internal") 
Uri audiosUri = MediaStore.Audio.Media.getContentUri("external"); 

Log.d("audiosUri = " + audiosUri.toString(),""); 

String[] projection = {MediaStore.Audio.AudioColumns.DATA,MediaStore.Audio.AudioColumns.DISPLAY_NAME,MediaStore.Audio.AudioColumns.DURATION}; 

// TODO This will break if we have no matching item in the MediaStore. 
Cursor cursor = managedQuery(audiosUri, projection, MediaStore.Audio.AudioColumns.DATA + " LIKE ?", new String[] { filepath }, null); 
cursor.moveToFirst(); 

path =cursor.getString(cursor.getColumnIndex(projection[0])); 
name=cursor.getString(cursor.getColumnIndex(projection[1])); 
int iduration = cursor.getColumnIndex(projection[2]); 
duration=CalTotalTime(Integer.valueOf(iduration)); 
Log.d("pathhhhhhhhhhhhhhhhhh", path); 
Log.d("nameeeeeeeeeeeeeeeeeeeeeee", name); 
Log.d("duration", duration); 

cursor.close(); 

너무이 링크를 참조