【发布时间】:2015-02-25 13:34:23
【问题描述】:
我想在从 MediaStore.Audio 挑选歌曲后播放它。我得到了 URi 并在烘烤后进行了测试。但它没有使用媒体播放器播放。
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 1234);
在 ActivityResult 上
if(requestCode == 1234 && resultCode == RESULT_OK)
{
Uri fortsting = getIntent().getData();
Uri uriSound= data.getData();
Toast.makeText(context, "USound " + uriSound.toString() + " tsting "+ fortsting.toString() , Toast.LENGTH_LONG).show();
//String extra = getRealPathFromURI(uriSound);
try
{
playSong(uriSound);
}
catch (IllegalArgumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalStateException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
//play(extra);
}
我也尝试使用 getRealPath
private String getRealPathFromURI(Uri contentUri)
{
String[] proj = { MediaStore.Audio.Media.DATA };
CursorLoader loader = new CursorLoader(context, contentUri, proj, null, null, null);
Cursor cursor = loader.loadInBackground();
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
if(cursor.getCount()==0 || cursor==null)
return null;
cursor.moveToFirst();
return cursor.getString(column_index);
}
【问题讨论】:
-
你的 playSong(uriSound) 在哪里?方法?
标签: android mediastore