Change how unfilled songs are handled
* Remove code checks for -1 and path == null, it's the job of the creator of a Song object to not inject unfilled songs into the timeline
This commit is contained in:
parent
c7653c7051
commit
305a7c1823
@ -51,7 +51,7 @@ public class AudioPickerActivity extends PlaybackActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mSong = getSongForUri(uri);
|
mSong = getSongForUri(uri);
|
||||||
if (mSong.isEmpty()) {
|
if (mSong == null) {
|
||||||
// unsupported intent or song not found
|
// unsupported intent or song not found
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
@ -113,7 +113,7 @@ public class AudioPickerActivity extends PlaybackActivity {
|
|||||||
* Attempts to resolve given uri to a song object
|
* Attempts to resolve given uri to a song object
|
||||||
*
|
*
|
||||||
* @param uri The uri to resolve
|
* @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) {
|
private Song getSongForUri(Uri uri) {
|
||||||
Song song = new Song(-1);
|
Song song = new Song(-1);
|
||||||
@ -130,7 +130,7 @@ public class AudioPickerActivity extends PlaybackActivity {
|
|||||||
}
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
return song;
|
return song.isFilled() ? song : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -594,10 +594,8 @@ public class FullPlaybackActivity extends PlaybackActivity
|
|||||||
}
|
}
|
||||||
mFormat = sb.toString();
|
mFormat = sb.toString();
|
||||||
|
|
||||||
if(song.path != null) { /* ICS bug? */
|
|
||||||
float[] rg = PlaybackService.get(this).getReplayGainValues(song.path);
|
float[] rg = PlaybackService.get(this).getReplayGainValues(song.path);
|
||||||
mReplayGain = "track="+rg[0]+"dB, album="+rg[1]+"dB";
|
mReplayGain = "track="+rg[0]+"dB, album="+rg[1]+"dB";
|
||||||
}
|
|
||||||
|
|
||||||
data.release();
|
data.release();
|
||||||
}
|
}
|
||||||
|
@ -412,7 +412,7 @@ public class MediaUtils {
|
|||||||
}
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
return song.isEmpty() ? null : song;
|
return song.isFilled() ? song : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -738,7 +738,6 @@ public final class PlaybackService extends Service
|
|||||||
Song nextSong = getSong(1);
|
Song nextSong = getSong(1);
|
||||||
|
|
||||||
if( nextSong != null
|
if( nextSong != null
|
||||||
&& nextSong.path != null
|
|
||||||
&& fa != SongTimeline.FINISH_REPEAT_CURRENT
|
&& fa != SongTimeline.FINISH_REPEAT_CURRENT
|
||||||
&& fa != SongTimeline.FINISH_STOP_CURRENT
|
&& fa != SongTimeline.FINISH_STOP_CURRENT
|
||||||
&& !mTimeline.isEndOfQueue() ) {
|
&& !mTimeline.isEndOfQueue() ) {
|
||||||
@ -1279,7 +1278,7 @@ public final class PlaybackService extends Service
|
|||||||
else
|
else
|
||||||
song = mTimeline.shiftCurrentSong(delta);
|
song = mTimeline.shiftCurrentSong(delta);
|
||||||
mCurrentSong = song;
|
mCurrentSong = song;
|
||||||
if (song == null || song.isEmpty()) {
|
if (song == null) {
|
||||||
if (MediaUtils.isSongAvailable(getContentResolver())) {
|
if (MediaUtils.isSongAvailable(getContentResolver())) {
|
||||||
int flag = finishAction(mState) == SongTimeline.FINISH_RANDOM ? FLAG_ERROR : FLAG_EMPTY_QUEUE;
|
int flag = finishAction(mState) == SongTimeline.FINISH_RANDOM ? FLAG_ERROR : FLAG_EMPTY_QUEUE;
|
||||||
synchronized (mStateLock) {
|
synchronized (mStateLock) {
|
||||||
@ -1325,7 +1324,7 @@ public final class PlaybackService extends Service
|
|||||||
mPreparedMediaPlayer = tmpPlayer; // this was mMediaPlayer and is in reset() state
|
mPreparedMediaPlayer = tmpPlayer; // this was mMediaPlayer and is in reset() state
|
||||||
Log.v("VanillaMusic", "Swapped media players");
|
Log.v("VanillaMusic", "Swapped media players");
|
||||||
}
|
}
|
||||||
else if(song.path != null) {
|
else {
|
||||||
prepareMediaPlayer(mMediaPlayer, song.path);
|
prepareMediaPlayer(mMediaPlayer, song.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ public class RemoteControl {
|
|||||||
|
|
||||||
remote.setPlaybackState(isPlaying ? RemoteControlClient.PLAYSTATE_PLAYING : RemoteControlClient.PLAYSTATE_PAUSED);
|
remote.setPlaybackState(isPlaying ? RemoteControlClient.PLAYSTATE_PLAYING : RemoteControlClient.PLAYSTATE_PAUSED);
|
||||||
RemoteControlClient.MetadataEditor editor = remote.editMetadata(true);
|
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_ARTIST, song.artist);
|
||||||
editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, song.album);
|
editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, song.album);
|
||||||
editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, song.title);
|
editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, song.title);
|
||||||
|
@ -157,11 +157,11 @@ public class Song implements Comparable<Song> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,6 +37,7 @@ import java.util.Comparator;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the list of currently playing songs, implements repeat and shuffle
|
* 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
|
// The query may have returned zero results or we might
|
||||||
// have failed to populate some songs: Get rid of all
|
// have failed to populate some songs: Get rid of all
|
||||||
// uninitialized items (where path == null)
|
// uninitialized items
|
||||||
Iterator<Song> it = songs.iterator();
|
Iterator<Song> it = songs.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Song e = it.next();
|
Song e = it.next();
|
||||||
if (e.path == null) {
|
if (e.isFilled() == false) {
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -683,7 +684,8 @@ public final class SongTimeline {
|
|||||||
int type = query.type;
|
int type = query.type;
|
||||||
long data = query.data;
|
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) {
|
if (count == 0 && type == MediaUtils.TYPE_FILE && query.selectionArgs.length == 1) {
|
||||||
String pathQuery = query.selectionArgs[0];
|
String pathQuery = query.selectionArgs[0];
|
||||||
@ -743,9 +745,16 @@ public final class SongTimeline {
|
|||||||
|
|
||||||
for (int j = 0; j != count; ++j) {
|
for (int j = 0; j != count; ++j) {
|
||||||
cursor.moveToPosition(j);
|
cursor.moveToPosition(j);
|
||||||
|
|
||||||
Song song = new Song(-1);
|
Song song = new Song(-1);
|
||||||
song.populate(cursor);
|
song.populate(cursor);
|
||||||
|
if (song.isFilled() == false) {
|
||||||
|
// Song vanished from device for some reason: we are silently skipping it.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
timeline.add(addAtPos++, song);
|
timeline.add(addAtPos++, song);
|
||||||
|
added++;
|
||||||
|
|
||||||
if (jumpSong == null) {
|
if (jumpSong == null) {
|
||||||
if ((mode == MODE_PLAY_POS_FIRST || mode == MODE_ENQUEUE_POS_FIRST) && j == data) {
|
if ((mode == MODE_PLAY_POS_FIRST || mode == MODE_ENQUEUE_POS_FIRST) && j == data) {
|
||||||
@ -790,7 +799,7 @@ public final class SongTimeline {
|
|||||||
|
|
||||||
changed();
|
changed();
|
||||||
|
|
||||||
return count;
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user