diff --git a/src/de/danoeh/antennapod/service/playback/PlaybackService.java b/src/de/danoeh/antennapod/service/playback/PlaybackService.java index 6cebce02c..f71ab0f95 100644 --- a/src/de/danoeh/antennapod/service/playback/PlaybackService.java +++ b/src/de/danoeh/antennapod/service/playback/PlaybackService.java @@ -363,6 +363,10 @@ public class PlaybackService extends Service { public void statusChanged(PlaybackServiceMediaPlayer.PSMPInfo newInfo) { currentMediaType = mediaPlayer.getCurrentMediaType(); switch (newInfo.playerStatus) { + case INITIALIZED: + writePlaybackPreferences(); + break; + case PREPARED: taskManager.startChapterLoader(newInfo.playable); break; @@ -385,7 +389,6 @@ public class PlaybackService extends Service { if (AppConfig.DEBUG) Log.d(TAG, "Resuming/Starting playback"); - writePlaybackPreferences(); taskManager.startPositionSaver(); taskManager.startWidgetUpdater(); setupNotification(newInfo); @@ -444,7 +447,7 @@ public class PlaybackService extends Service { @Override public boolean endPlayback(boolean playNextEpisode) { - endPlayback(true); + PlaybackService.this.endPlayback(true); return true; } diff --git a/src/de/danoeh/antennapod/service/playback/PlaybackServiceMediaPlayer.java b/src/de/danoeh/antennapod/service/playback/PlaybackServiceMediaPlayer.java index f6e749324..da273cc0e 100644 --- a/src/de/danoeh/antennapod/service/playback/PlaybackServiceMediaPlayer.java +++ b/src/de/danoeh/antennapod/service/playback/PlaybackServiceMediaPlayer.java @@ -112,8 +112,13 @@ public class PlaybackServiceMediaPlayer { @Override public void run() { playerLock.lock(); - playMediaObject(playable, false, stream, startWhenPrepared, prepareImmediately); - playerLock.unlock(); + try { + playMediaObject(playable, false, stream, startWhenPrepared, prepareImmediately); + } catch (RuntimeException e) { + throw e; + } finally { + playerLock.unlock(); + } } }); } @@ -145,11 +150,12 @@ public class PlaybackServiceMediaPlayer { setPlayerStatus(PlayerStatus.INDETERMINATE, null); } } - createMediaPlayer(); + this.media = playable; this.stream = stream; this.mediaType = media.getMediaType(); this.videoSize = null; + createMediaPlayer(); PlaybackServiceMediaPlayer.this.startWhenPrepared.set(startWhenPrepared); setPlayerStatus(PlayerStatus.INITIALIZING, media); try { @@ -313,8 +319,10 @@ public class PlaybackServiceMediaPlayer { void onPrepared(final boolean startWhenPrepared) { playerLock.lock(); - if (playerStatus != PlayerStatus.PREPARING) + if (playerStatus != PlayerStatus.PREPARING) { + playerLock.unlock(); throw new IllegalStateException("Player is not in PREPARING state"); + } if (AppConfig.DEBUG) Log.d(TAG, "Resource prepared"); @@ -760,34 +768,9 @@ public class PlaybackServiceMediaPlayer { public RemoteControlClient getRemoteControlClient(); } - private final com.aocate.media.MediaPlayer.OnPreparedListener audioPreparedListener = new com.aocate.media.MediaPlayer.OnPreparedListener() { - @Override - public void onPrepared(final com.aocate.media.MediaPlayer mp) { - executor.submit(new Runnable() { - @Override - public void run() { - PlaybackServiceMediaPlayer.this.onPrepared(startWhenPrepared.get()); - } - }); - } - }; - - private final android.media.MediaPlayer.OnPreparedListener videoPreparedListener = new android.media.MediaPlayer.OnPreparedListener() { - @Override - public void onPrepared(android.media.MediaPlayer mp) { - executor.submit(new Runnable() { - @Override - public void run() { - PlaybackServiceMediaPlayer.this.onPrepared(startWhenPrepared.get()); - } - }); - } - }; - private IPlayer setMediaPlayerListeners(IPlayer mp) { if (mp != null && media != null) { if (media.getMediaType() == MediaType.AUDIO) { - ((AudioPlayer) mp).setOnPreparedListener(audioPreparedListener); ((AudioPlayer) mp) .setOnCompletionListener(audioCompletionListener); ((AudioPlayer) mp) @@ -797,7 +780,6 @@ public class PlaybackServiceMediaPlayer { .setOnBufferingUpdateListener(audioBufferingUpdateListener); ((AudioPlayer) mp).setOnInfoListener(audioInfoListener); } else { - ((VideoPlayer) mp).setOnPreparedListener(videoPreparedListener); ((VideoPlayer) mp) .setOnCompletionListener(videoCompletionListener); ((VideoPlayer) mp)