select the song path aswell

This commit is contained in:
tibbi 2016-03-23 18:32:03 +01:00
parent 9daaedfdc1
commit 7b874c9b30
2 changed files with 20 additions and 3 deletions

View file

@ -146,19 +146,29 @@ public class MusicService extends Service
private void fillPlaylist() {
songs.clear();
final Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
final Cursor cursor = getContentResolver().query(uri, null, null, null, null);
final String[] columns = {
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.DATA
};
final Cursor cursor = getContentResolver().query(uri, columns, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
final int idIndex = cursor.getColumnIndex(MediaStore.Audio.Media._ID);
final int titleIndex = cursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
final int artistIndex = cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
final int durationIndex = cursor.getColumnIndex(MediaStore.Audio.Media.DURATION);
final int pathIndex = cursor.getColumnIndex(MediaStore.Audio.Media.DATA);
do {
if (cursor.getInt(durationIndex) > MIN_DURATION_MS) {
final long id = cursor.getLong(idIndex);
final String title = cursor.getString(titleIndex);
final String artist = cursor.getString(artistIndex);
songs.add(new Song(id, title, artist));
final String path = cursor.getString(pathIndex);
songs.add(new Song(id, title, artist, path));
}
} while (cursor.moveToNext());
cursor.close();

View file

@ -4,11 +4,13 @@ public class Song {
private long id;
private String title;
private String artist;
private String path;
public Song(long id, String title, String artist) {
public Song(long id, String title, String artist, String path) {
this.id = id;
this.title = title;
this.artist = artist;
this.path = path;
}
public long getId() {
@ -23,12 +25,17 @@ public class Song {
return title;
}
public String getPath() {
return path;
}
@Override
public String toString() {
return "Song{"
+ "id=" + getId()
+ ", title=" + getTitle()
+ ", artist=" + getArtist()
+ ", path=" + getPath()
+ "}";
}
}