ContentResolver contentResolver = getContentResolver();
Код: Выделить всё
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor cursor = contentResolver.query(uri, null, MediaStore.Audio.Media.DATA + "LIKE?", new String[]{"%.mp3"},null);
if(cursor == null){
Toast.makeText(this,"Something Went Wrong!!!",Toast.LENGTH_SHORT).show();
}
else if(!cursor.moveToNext()){
Toast.makeText(this, "No Music File Found !!!", Toast.LENGTH_SHORT).show();
}
else{
while(cursor.moveToNext()){
final String getMusicFileName = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
final String getArtistName = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
long cursorId = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media._ID));
Uri musicFileUri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, cursorId);
String getDuration = "00:00";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
getDuration = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.AudioColumns.DURATION));
final MusicList musicList = new MusicList(getMusicFileName , getArtistName, getDuration, false , musicFileUri);
musicLists.add(musicList);
}
}
musicRecyclerView.setAdapter(new MusicAdapter(musicLists, MainActivity.this));
}
}
cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
final String getArtistName = курсор.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
long курсорId = курсор.getLong(cursor.getColumnIndex(MediaStore.Audio.Media._ID));В этих частях
Я попробовал добавить @SuppressLint("Range"), но это не сработало должным образом. Я делал музыкальный проигрыватель
Подробнее здесь: https://stackoverflow.com/questions/781 ... n-solution
Мобильная версия