Handle corrupt/missing songs better
The old behavior would try to skip the song automatically and not tell the user what was happening. The new behavior shows a Toast and stops playback.
This commit is contained in:
parent
bd0596cd9e
commit
b8f3e3819f
@ -37,6 +37,7 @@ THE SOFTWARE.
|
|||||||
<string name="repeat_disable">Disable Repeat</string>
|
<string name="repeat_disable">Disable Repeat</string>
|
||||||
<string name="repeat_enabling">Repeat enabled. The current song and any songs you have added after it will be repeated.</string>
|
<string name="repeat_enabling">Repeat enabled. The current song and any songs you have added after it will be repeated.</string>
|
||||||
<string name="repeat_disabling">Repeat disabled</string>
|
<string name="repeat_disabling">Repeat disabled</string>
|
||||||
|
<string name="song_load_failed">Failed to load song %s. It may be corrupt or missing.</string>
|
||||||
|
|
||||||
<!-- Widgets -->
|
<!-- Widgets -->
|
||||||
<string name="starting">Starting up...</string>
|
<string name="starting">Starting up...</string>
|
||||||
|
@ -146,7 +146,11 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
|||||||
public static final int FLAG_PLAYING = 0x1;
|
public static final int FLAG_PLAYING = 0x1;
|
||||||
public static final int FLAG_SHUFFLE = 0x4;
|
public static final int FLAG_SHUFFLE = 0x4;
|
||||||
public static final int FLAG_REPEAT = 0x8;
|
public static final int FLAG_REPEAT = 0x8;
|
||||||
public static final int ALL_FLAGS = FLAG_NO_MEDIA + FLAG_PLAYING + FLAG_SHUFFLE + FLAG_REPEAT;
|
/**
|
||||||
|
* Set when the current song is unplayable.
|
||||||
|
*/
|
||||||
|
public static final int FLAG_ERROR = 0x10;
|
||||||
|
public static final int ALL_FLAGS = FLAG_NO_MEDIA + FLAG_PLAYING + FLAG_SHUFFLE + FLAG_REPEAT + FLAG_ERROR;
|
||||||
/**
|
/**
|
||||||
* The flags that are (usually) only toggled by user action.
|
* The flags that are (usually) only toggled by user action.
|
||||||
*/
|
*/
|
||||||
@ -454,6 +458,13 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
|||||||
state &= ~FLAG_PLAYING;
|
state &= ~FLAG_PLAYING;
|
||||||
|
|
||||||
Song song = getSong(0);
|
Song song = getSong(0);
|
||||||
|
|
||||||
|
if ((state & FLAG_ERROR) != 0 && (state & FLAG_PLAYING) != 0) {
|
||||||
|
state &= ~FLAG_PLAYING;
|
||||||
|
String text = getResources().getString(R.string.song_load_failed, song == null ? null : song.path);
|
||||||
|
Toast.makeText(this, text, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
|
||||||
if (song == null && (state & FLAG_PLAYING) != 0)
|
if (song == null && (state & FLAG_PLAYING) != 0)
|
||||||
return;
|
return;
|
||||||
if (song == null)
|
if (song == null)
|
||||||
@ -574,6 +585,10 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
|||||||
unsetFlag(FLAG_NO_MEDIA);
|
unsetFlag(FLAG_NO_MEDIA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure that we broadcast a change event even if we play the same
|
||||||
|
// song again.
|
||||||
|
mLastSongBroadcast = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
synchronized (mMediaPlayer) {
|
synchronized (mMediaPlayer) {
|
||||||
mMediaPlayer.reset();
|
mMediaPlayer.reset();
|
||||||
@ -584,11 +599,11 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
|||||||
}
|
}
|
||||||
if ((mState & FLAG_PLAYING) != 0)
|
if ((mState & FLAG_PLAYING) != 0)
|
||||||
mMediaPlayer.start();
|
mMediaPlayer.start();
|
||||||
// Ensure that we broadcast a change event even if we play the same
|
updateState(mState & ~FLAG_ERROR);
|
||||||
// song again.
|
|
||||||
mLastSongBroadcast = null;
|
|
||||||
updateState(mState);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
// FLAG_PLAYING is set to force showing the Toast. updateState()
|
||||||
|
// will unset it.
|
||||||
|
updateState(mState | FLAG_PLAYING | FLAG_ERROR);
|
||||||
Log.e("VanillaMusic", "IOException", e);
|
Log.e("VanillaMusic", "IOException", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -609,12 +624,8 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
|||||||
public boolean onError(MediaPlayer player, int what, int extra)
|
public boolean onError(MediaPlayer player, int what, int extra)
|
||||||
{
|
{
|
||||||
Log.e("VanillaMusic", "MediaPlayer error: " + what + " " + extra);
|
Log.e("VanillaMusic", "MediaPlayer error: " + what + " " + extra);
|
||||||
mMediaPlayer.reset();
|
if (!Song.isSongAvailable())
|
||||||
Song song = getSong(+1);
|
|
||||||
if (song != null && !song.query(true))
|
|
||||||
setFlag(FLAG_NO_MEDIA);
|
setFlag(FLAG_NO_MEDIA);
|
||||||
else
|
|
||||||
mHandler.sendEmptyMessage(TRACK_CHANGED);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -704,7 +715,12 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
|||||||
@Override
|
@Override
|
||||||
public void onChange(boolean selfChange)
|
public void onChange(boolean selfChange)
|
||||||
{
|
{
|
||||||
setCurrentSong(0);
|
if (Song.isSongAvailable()) {
|
||||||
|
if ((mState & FLAG_NO_MEDIA) != 0)
|
||||||
|
setCurrentSong(0);
|
||||||
|
} else {
|
||||||
|
setFlag(FLAG_NO_MEDIA);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user