Improved stability of playbackService when handling an Error

This commit is contained in:
daniel oeh 2012-07-02 17:38:59 +02:00
parent 4882a5ff92
commit f2fe9553de
2 changed files with 8 additions and 1 deletions

View File

@ -559,6 +559,7 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
public class MediaPositionObserver extends public class MediaPositionObserver extends
AsyncTask<MediaPlayer, Void, Void> { AsyncTask<MediaPlayer, Void, Void> {
private static final String TAG = "MediaPositionObserver";
private static final int WAITING_INTERVALL = 1000; private static final int WAITING_INTERVALL = 1000;
private MediaPlayer player; private MediaPlayer player;
@ -579,6 +580,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
Log.d(TAG, Log.d(TAG,
"Thread was interrupted while waiting. Finishing now"); "Thread was interrupted while waiting. Finishing now");
return null; return null;
} catch (IllegalStateException e) {
Log.d(TAG, "player is in illegal state, exiting now");
} }
publishProgress(); publishProgress();
} }

View File

@ -523,12 +523,16 @@ public class PlaybackService extends Service {
while (!isCancelled() && player.isPlaying()) { while (!isCancelled() && player.isPlaying()) {
try { try {
Thread.sleep(WAITING_INTERVALL); Thread.sleep(WAITING_INTERVALL);
saveCurrentPosition();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Log.d(TAG, Log.d(TAG,
"Thread was interrupted while waiting. Finishing now..."); "Thread was interrupted while waiting. Finishing now...");
return null; return null;
} catch (IllegalStateException e) {
Log.d(TAG, "Player is in illegal state. Finishing now");
return null;
} }
saveCurrentPosition();
} }
return null; return null;
} }