Commit dc144e3c authored by linus_lee's avatar linus_lee Committed by Steve Kondik
Browse files

Eleven: Show error message for corrupt tracks (additional codepaths)

Add showing error message for code paths where the media player fails gracefully
Unfortunately adding the logic to remove the bad track is not trivial because the
removeTracks logic automatically does other things to try to go to the next track.
For now I will leave the logic so that it goes on to the next track and make a note
on the music service rewrite notes to cover this scenario as well.

Change-Id: Ib7ae5ce7819b15cdb3ada4995bc0734ab2d9b0a2
parent 04f294bf
...@@ -166,7 +166,7 @@ ...@@ -166,7 +166,7 @@
<string name="empty_generic_secondary">To copy music from your computer to your device, use a USB cable.</string> <string name="empty_generic_secondary">To copy music from your computer to your device, use a USB cable.</string>
<string name="empty_queue_main">No songs in play queue</string> <string name="empty_queue_main">No songs in play queue</string>
<string name="empty_queue_secondary">To add songs to your Play Queue, tap the options menu on a song, album, or artist and select \"Add to queue\".</string> <string name="empty_queue_secondary">To add songs to your Play Queue, tap the options menu on a song, album, or artist and select \"Add to queue\".</string>
<string name="error_playing_track">Unable to play track %1$s, removing it from the queue</string> <string name="error_playing_track">Unable to play track %1$s</string>
<!-- Section Headers --> <!-- Section Headers -->
<string name="header_unknown_year">Unknown year</string> <string name="header_unknown_year">Unknown year</string>
......
...@@ -1156,6 +1156,8 @@ public class MusicPlaybackService extends Service { ...@@ -1156,6 +1156,8 @@ public class MusicPlaybackService extends Service {
} }
stop(false); stop(false);
boolean shutdown = false;
updateCursor(mPlaylist.get(mPlayPos).mId); updateCursor(mPlaylist.get(mPlayPos).mId);
while (true) { while (true) {
if (mCursor != null if (mCursor != null
...@@ -1163,6 +1165,7 @@ public class MusicPlaybackService extends Service { ...@@ -1163,6 +1165,7 @@ public class MusicPlaybackService extends Service {
+ mCursor.getLong(IDCOLIDX))) { + mCursor.getLong(IDCOLIDX))) {
break; break;
} }
// if we get here then opening the file failed. We can close the // if we get here then opening the file failed. We can close the
// cursor now, because // cursor now, because
// we're either going to create a new one next, or stop trying // we're either going to create a new one next, or stop trying
...@@ -1170,12 +1173,8 @@ public class MusicPlaybackService extends Service { ...@@ -1170,12 +1173,8 @@ public class MusicPlaybackService extends Service {
if (mOpenFailedCounter++ < 10 && mPlaylist.size() > 1) { if (mOpenFailedCounter++ < 10 && mPlaylist.size() > 1) {
final int pos = getNextPosition(false); final int pos = getNextPosition(false);
if (pos < 0) { if (pos < 0) {
scheduleDelayedShutdown(); shutdown = true;
if (mIsSupposedToBePlaying) { break;
mIsSupposedToBePlaying = false;
notifyChange(PLAYSTATE_CHANGED);
}
return;
} }
mPlayPos = pos; mPlayPos = pos;
stop(false); stop(false);
...@@ -1184,20 +1183,29 @@ public class MusicPlaybackService extends Service { ...@@ -1184,20 +1183,29 @@ public class MusicPlaybackService extends Service {
} else { } else {
mOpenFailedCounter = 0; mOpenFailedCounter = 0;
Log.w(TAG, "Failed to open file for playback"); Log.w(TAG, "Failed to open file for playback");
shutdown = true;
break;
}
}
if (shutdown) {
scheduleDelayedShutdown(); scheduleDelayedShutdown();
if (mIsSupposedToBePlaying) { if (mIsSupposedToBePlaying) {
mIsSupposedToBePlaying = false; mIsSupposedToBePlaying = false;
notifyChange(PLAYSTATE_CHANGED); notifyChange(PLAYSTATE_CHANGED);
} }
return; } else if (openNext) {
}
}
if (openNext) {
setNextTrack(); setNextTrack();
} }
} }
} }
private void sendErrorMessage(final String trackName) {
final Intent i = new Intent(TRACK_ERROR);
i.putExtra(TrackErrorExtra.TRACK_NAME, trackName);
sendBroadcast(i);
}
/** /**
* @param force True to force the player onto the track next, false * @param force True to force the player onto the track next, false
* otherwise. * otherwise.
...@@ -1727,6 +1735,13 @@ public class MusicPlaybackService extends Service { ...@@ -1727,6 +1735,13 @@ public class MusicPlaybackService extends Service {
mOpenFailedCounter = 0; mOpenFailedCounter = 0;
return true; return true;
} }
String trackName = getTrackName();
if (TextUtils.isEmpty(trackName)) {
trackName = path;
}
sendErrorMessage(trackName);
stop(true); stop(true);
return false; return false;
} }
...@@ -1989,7 +2004,7 @@ public class MusicPlaybackService extends Service { ...@@ -1989,7 +2004,7 @@ public class MusicPlaybackService extends Service {
*/ */
public String getGenreName() { public String getGenreName() {
synchronized (this) { synchronized (this) {
if (mCursor == null) { if (mCursor == null || mPlayPos < 0 || mPlayPos >= mPlaylist.size()) {
return null; return null;
} }
String[] genreProjection = { MediaStore.Audio.Genres.NAME }; String[] genreProjection = { MediaStore.Audio.Genres.NAME };
...@@ -2813,10 +2828,8 @@ public class MusicPlaybackService extends Service { ...@@ -2813,10 +2828,8 @@ public class MusicPlaybackService extends Service {
break; break;
case SERVER_DIED: case SERVER_DIED:
if (service.isPlaying()) { if (service.isPlaying()) {
final Intent i = new Intent(TRACK_ERROR);
final TrackErrorInfo info = (TrackErrorInfo)msg.obj; final TrackErrorInfo info = (TrackErrorInfo)msg.obj;
i.putExtra(TrackErrorExtra.TRACK_NAME, info.mTrackName); service.sendErrorMessage(info.mTrackName);
service.sendBroadcast(i);
// since the service isPlaying(), we only need to remove the offending // since the service isPlaying(), we only need to remove the offending
// audio track, and the code will automatically play the next track // audio track, and the code will automatically play the next track
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment