满意答案
ZAKEYA
2013.11.03
采纳率:44% 等级:12
已帮助:8407人
ContentValues values = new ContentValues(3);
long current = System.currentTimeMillis();
values.put(MediaColumns.TITLE, "My Audio record");
values.put(MediaColumns.DATE_ADDED, (int) (current / 1000));
values.put(MediaColumns.MIME_TYPE, "audio/mp3");
values.put(MediaColumns.DATA, file.getAbsolutePath());
ContentResolver contentResolver = getContentResolver();
Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Uri newUri = contentResolver.insert(base, values);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, newUri));
pathUri = file.getAbsolutePath();
//读取音频文件的数据
BufferedInputStream bufferIn;
try {
bufferIn = new BufferedInputStream(new FileInputStream(pathUri));
Log.v(TAG, "打开文件的路径:" + pathUri);
byte[] buffer = new byte[1024];
int length=-1;
while(true){
length=bufferIn.read(buffer);
if(length <=0){
break;
}
//这样不是得到数据了吗,存在buffer中,有length个
}
Log.e(TAG, buffer.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
00分享举报