0
我創建的音頻播放器,我使用此代碼來獲取所有的歌曲如何避免不支持的格式的音頻播放器
String[] STAR = {"*"};
Cursor cursor;
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
File file;
cursor =context.getContentResolver().query(uri, STAR, selection, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
int i = 0;
do {
String songName = cursor
.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
path[i] = cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.DATA));
String albumName = cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.ALBUM));
albumId[i] = cursor
.getInt(cursor
.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
String artist= cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
String albumname= cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM));
artistId[i]=cursor.getInt(cursor
.getColumnIndex(MediaStore.Audio.Media.ARTIST_ID));
}cursor.close();
這讓我的歌,但我得到的不支持的格式的音頻太多。如.wav任何想法如何避免不受支持的格式
你需要添加的MimeType檢查。請查看如何添加支票的示例。 – Geek