diff --git a/src/ch/blinkenlights/android/vanilla/AudioPickerActivity.java b/src/ch/blinkenlights/android/vanilla/AudioPickerActivity.java index b5febc40..ad9354e6 100644 --- a/src/ch/blinkenlights/android/vanilla/AudioPickerActivity.java +++ b/src/ch/blinkenlights/android/vanilla/AudioPickerActivity.java @@ -51,7 +51,7 @@ public class AudioPickerActivity extends PlaybackActivity { } mSong = getSongForUri(uri); - if (mSong.isEmpty()) { + if (mSong == null) { // unsupported intent or song not found finish(); return; @@ -113,7 +113,7 @@ public class AudioPickerActivity extends PlaybackActivity { * Attempts to resolve given uri to a song object * * @param uri The uri to resolve - * @return A song object, id will be -1 on failure + * @return A song object, null on failure */ private Song getSongForUri(Uri uri) { Song song = new Song(-1); @@ -130,7 +130,7 @@ public class AudioPickerActivity extends PlaybackActivity { } cursor.close(); } - return song; + return song.isFilled() ? song : null; } } diff --git a/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java b/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java index 310a6101..9fb4ca1b 100644 --- a/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java +++ b/src/ch/blinkenlights/android/vanilla/FullPlaybackActivity.java @@ -594,10 +594,8 @@ public class FullPlaybackActivity extends PlaybackActivity } mFormat = sb.toString(); - if(song.path != null) { /* ICS bug? */ - float[] rg = PlaybackService.get(this).getReplayGainValues(song.path); - mReplayGain = "track="+rg[0]+"dB, album="+rg[1]+"dB"; - } + float[] rg = PlaybackService.get(this).getReplayGainValues(song.path); + mReplayGain = "track="+rg[0]+"dB, album="+rg[1]+"dB"; data.release(); } diff --git a/src/ch/blinkenlights/android/vanilla/MediaUtils.java b/src/ch/blinkenlights/android/vanilla/MediaUtils.java index a1d08297..65664486 100644 --- a/src/ch/blinkenlights/android/vanilla/MediaUtils.java +++ b/src/ch/blinkenlights/android/vanilla/MediaUtils.java @@ -412,7 +412,7 @@ public class MediaUtils { } cursor.close(); } - return song.isEmpty() ? null : song; + return song.isFilled() ? song : null; } /** diff --git a/src/ch/blinkenlights/android/vanilla/PlaybackService.java b/src/ch/blinkenlights/android/vanilla/PlaybackService.java index 1887b488..0951f39d 100644 --- a/src/ch/blinkenlights/android/vanilla/PlaybackService.java +++ b/src/ch/blinkenlights/android/vanilla/PlaybackService.java @@ -738,7 +738,6 @@ public final class PlaybackService extends Service Song nextSong = getSong(1); if( nextSong != null - && nextSong.path != null && fa != SongTimeline.FINISH_REPEAT_CURRENT && fa != SongTimeline.FINISH_STOP_CURRENT && !mTimeline.isEndOfQueue() ) { @@ -1279,7 +1278,7 @@ public final class PlaybackService extends Service else song = mTimeline.shiftCurrentSong(delta); mCurrentSong = song; - if (song == null || song.isEmpty()) { + if (song == null) { if (MediaUtils.isSongAvailable(getContentResolver())) { int flag = finishAction(mState) == SongTimeline.FINISH_RANDOM ? FLAG_ERROR : FLAG_EMPTY_QUEUE; synchronized (mStateLock) { @@ -1325,7 +1324,7 @@ public final class PlaybackService extends Service mPreparedMediaPlayer = tmpPlayer; // this was mMediaPlayer and is in reset() state Log.v("VanillaMusic", "Swapped media players"); } - else if(song.path != null) { + else { prepareMediaPlayer(mMediaPlayer, song.path); } diff --git a/src/ch/blinkenlights/android/vanilla/RemoteControl.java b/src/ch/blinkenlights/android/vanilla/RemoteControl.java index ba16df8e..0c8ecbc3 100644 --- a/src/ch/blinkenlights/android/vanilla/RemoteControl.java +++ b/src/ch/blinkenlights/android/vanilla/RemoteControl.java @@ -87,7 +87,7 @@ public class RemoteControl { remote.setPlaybackState(isPlaying ? RemoteControlClient.PLAYSTATE_PLAYING : RemoteControlClient.PLAYSTATE_PAUSED); RemoteControlClient.MetadataEditor editor = remote.editMetadata(true); - if (song != null && song.isEmpty() == false) { + if (song != null) { editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, song.artist); editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, song.album); editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, song.title); diff --git a/src/ch/blinkenlights/android/vanilla/Song.java b/src/ch/blinkenlights/android/vanilla/Song.java index 668894cf..3b4e3314 100644 --- a/src/ch/blinkenlights/android/vanilla/Song.java +++ b/src/ch/blinkenlights/android/vanilla/Song.java @@ -157,11 +157,11 @@ public class Song implements Comparable { } /** - * Returns true if the song is empty + * Returns true if the song is filled */ - public boolean isEmpty() + public boolean isFilled() { - return id == -1; + return (id != -1 && path != null); } /** diff --git a/src/ch/blinkenlights/android/vanilla/SongTimeline.java b/src/ch/blinkenlights/android/vanilla/SongTimeline.java index 4f72de63..9489b683 100644 --- a/src/ch/blinkenlights/android/vanilla/SongTimeline.java +++ b/src/ch/blinkenlights/android/vanilla/SongTimeline.java @@ -37,6 +37,7 @@ import java.util.Comparator; import java.util.Iterator; import java.util.ListIterator; import junit.framework.Assert; +import android.util.Log; /** * Contains the list of currently playing songs, implements repeat and shuffle @@ -363,11 +364,11 @@ public final class SongTimeline { // The query may have returned zero results or we might // have failed to populate some songs: Get rid of all - // uninitialized items (where path == null) + // uninitialized items Iterator it = songs.iterator(); while (it.hasNext()) { Song e = it.next(); - if (e.path == null) { + if (e.isFilled() == false) { it.remove(); } } @@ -683,7 +684,8 @@ public final class SongTimeline { int type = query.type; long data = query.data; - int count = cursor.getCount(); + int count = cursor.getCount(); // Items found by query + int added = 0; // Items actually added to the queue if (count == 0 && type == MediaUtils.TYPE_FILE && query.selectionArgs.length == 1) { String pathQuery = query.selectionArgs[0]; @@ -743,9 +745,16 @@ public final class SongTimeline { for (int j = 0; j != count; ++j) { cursor.moveToPosition(j); + Song song = new Song(-1); song.populate(cursor); + if (song.isFilled() == false) { + // Song vanished from device for some reason: we are silently skipping it. + continue; + } + timeline.add(addAtPos++, song); + added++; if (jumpSong == null) { if ((mode == MODE_PLAY_POS_FIRST || mode == MODE_ENQUEUE_POS_FIRST) && j == data) { @@ -790,7 +799,7 @@ public final class SongTimeline { changed(); - return count; + return added; } /**