android调用系统录音机或取声音文件后如何使用??
我通过以下代码调用系统录音机或取声音文件:
Intent intentFromRecord=new Intent();
intentFromRecord.setType("audio/*");
intentFromRecord.setAction(Intent.ACTION_GET_CONTENT);
intentFromRecord.putExtra("return-data", true);
startActivityForResult(intentFromRecord,2);
但是返回的Uri怎么样用?
Uri uri = data.getData();
把它转为String存在SharedPrefereces内,取出来通过parse转为uri,再用MediaPlayer的setDataSource的两个方法:
setDataSource (String path)
setDataSource tDataSource (Context context, Uri uri)
都无法将取得的文件播放?
我的需求是要么存下路径存起来,要么取时干脆将另存为一个文件。
请问应如何实现?请前辈指教!
(注:上次取图片也遇到这种情况,后来查了很久,通过以下代码实现了,但声音文件又不知道如何处理了)
Uri uri = data.getData(); //将返回的结果
ContentResolver cr = this.getContentResolver();
Bitmap bmp=null;
bmp = BitmapFactory.decodeStream(cr.openInputStream(uri));
再通过bmp.compress存为一个文件。