I´m building a music player with the media player in Android Studio. It works, but there´s one problem: At the beginning the method getMusic() (shown below) is collecting all the information (title, artist, path) of my music files in a certain folder, but when its finished my array list only contains 7 songs, but in my folder there are 16 songs. So why doesn´t my content resolver get all files? All these files on my mobile phone are ok and not broken. Hopefully, someone has an idea, thanks!
public void getMusic() {
ContentResolver contentResolver = getContentResolver();
Uri songUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.Audio.AudioColumns.DATA, MediaStore.Audio.AudioColumns.TITLE, MediaStore.Audio.AudioColumns.ALBUM, MediaStore.Audio.ArtistColumns.ARTIST,};
Cursor songCursor = contentResolver.query(songUri, projection, MediaStore.Audio.Media.DATA + " like ? ", new String[]{"%/storage/emulated/0/Download/Music/%"}, null, null);
Log.e("COUNT", "" + songCursor.getCount());
if (songCursor != null && songCursor.moveToFirst()) {
int songTitle = songCursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
int songArtist = songCursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
int songPath = songCursor.getColumnIndex((MediaStore.Audio.Media.DATA));
do {
String currentTitle = songCursor.getString(songTitle);
String currentArtist = songCursor.getString(songArtist);
String currentPath = songCursor.getString(songPath);
Uri uriSong = MediaStore.Audio.Media.getContentUriForPath(currentPath);
// Testing purposes
Log.e("TEST", "Name: " + currentTitle + " Artist: " + currentArtist + " Path: " + currentPath + uriSong.toString());
songList.add(new Song(currentPath, "Artist", currentPath));
} while (songCursor.moveToNext());
}
songCursor.close();
Log.e("LIST", "" + songList.size());
}
Ok, well... the solution is very simple: I copied the songs from my cloud to my mobile device. Never used another way, because it worked at the beginning. Today I justed picked a USB-C adapter with an usb stick and copied the songs onto that stick and from this stick onto my mobile device. And thats it. The cloud was the problem.