0

我希望我的应用程序从图库中选择一个视频。它使用以下代码来获取路径。

Intent i = new Intent(Intent.ACTION_GET_CONTENT); 
i.setType("video/*"); 
startActivityForResult(i,2); 

接着

 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 // TODO Auto-generated method stub

  if(resultCode==RESULT_OK){

      str = data.getData().getPath();
   //this.go();
      this.ko();
  }
 }

str存储路径。对于测试运行,它的值是/external/video/media/10,但它应该类似于/sdcard/DCIM/a.mp4使用MediaMetaDataRetriever. 怎么做 ?

4

1 回答 1

0

就您而言,(据我了解您的问题)

if(resultCode==RESULT_OK){
      str = getRealPathFromURI(data.getData());
   //this.go();
      this.ko();
  }

使用此函数从 Uri 获取真实路径..

功能:

public String getRealPathFromURI(Uri contentUri)
    {
        try
        {
            String[] proj = {MediaStore.Video.Media.DATA};
            Cursor cursor = managedQuery(contentUri, proj, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        }
        catch (Exception e)
        {
            return contentUri.getPath();
        }
    }
于 2012-06-14T11:19:25.523 回答