在Android上獲取本地音頻可以通過以下步驟實現(xiàn):
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
ContentResolver contentResolver = getContentResolver();
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String[] projection = { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DATA };
Cursor cursor = contentResolver.query(uri, projection, null, null, null);
if (cursor != null) {
while (cursor.moveToNext()) {
long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media._ID));
String title = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
// 在這里可以處理獲取到的音頻文件信息
}
cursor.close();
}
注意:以上代碼只是一個示例,具體的操作可以根據(jù)需求進行調(diào)整。