From c4e0078382c6ea048456e127cc887476d48a6686 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Sat, 7 Jun 2014 16:38:04 +0200 Subject: Bugfix: Playback could not be restarted in some cases. fixes #387 --- .../service/playback/PlaybackService.java | 1 + .../playback/PlaybackServiceMediaPlayer.java | 36 +++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) (limited to 'src/de') diff --git a/src/de/danoeh/antennapod/service/playback/PlaybackService.java b/src/de/danoeh/antennapod/service/playback/PlaybackService.java index fb2569bfd..b7ff62129 100644 --- a/src/de/danoeh/antennapod/service/playback/PlaybackService.java +++ b/src/de/danoeh/antennapod/service/playback/PlaybackService.java @@ -541,6 +541,7 @@ public class PlaybackService extends Service { (nextMedia.getMediaType() == MediaType.VIDEO) ? EXTRA_CODE_VIDEO : EXTRA_CODE_AUDIO); } else { sendNotificationBroadcast(NOTIFICATION_TYPE_PLAYBACK_END, 0); + mediaPlayer.stop(); //stopSelf(); } } diff --git a/src/de/danoeh/antennapod/service/playback/PlaybackServiceMediaPlayer.java b/src/de/danoeh/antennapod/service/playback/PlaybackServiceMediaPlayer.java index 24ff9b3fa..2915da5a1 100644 --- a/src/de/danoeh/antennapod/service/playback/PlaybackServiceMediaPlayer.java +++ b/src/de/danoeh/antennapod/service/playback/PlaybackServiceMediaPlayer.java @@ -77,7 +77,8 @@ public class PlaybackServiceMediaPlayer { public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { if (BuildConfig.DEBUG) Log.d(TAG, "Rejected execution of runnable"); } - }); + } + ); mediaPlayer = null; statusBeforeSeeking = null; @@ -150,6 +151,8 @@ public class PlaybackServiceMediaPlayer { if (media != null) { if (!forceReset && media.getIdentifier().equals(playable.getIdentifier())) { // episode is already playing -> ignore method call + if (BuildConfig.DEBUG) + Log.d(TAG, "Method call to playMediaObject was ignored: media file already playing."); return; } else { // stop playback of this episode @@ -284,7 +287,8 @@ public class PlaybackServiceMediaPlayer { reinit(); } } else { - if (BuildConfig.DEBUG) Log.d(TAG, "Ignoring call to pause: Player is in " + playerStatus + " state"); + if (BuildConfig.DEBUG) + Log.d(TAG, "Ignoring call to pause: Player is in " + playerStatus + " state"); } playerLock.unlock(); @@ -385,9 +389,10 @@ public class PlaybackServiceMediaPlayer { /** * Seeks to the specified position. If the PSMP object is in an invalid state, this method will do nothing. + * * @param t The position to seek to in milliseconds. t < 0 will be interpreted as t = 0 - *

- * This method is executed on the caller's thread. + *

+ * This method is executed on the caller's thread. */ private void seekToSync(int t) { if (t < 0) { @@ -757,6 +762,29 @@ public class PlaybackServiceMediaPlayer { }); } + /** + * Moves the PlaybackServiceMediaPlayer into STOPPED state. This call is only valid if the player is currently in + * INDETERMINATE state, for example after a call to endPlayback. + * This method will only take care of changing the PlayerStatus of this object! Other tasks like + * abandoning audio focus have to be done with other methods. + */ + public void stop() { + executor.submit(new Runnable() { + @Override + public void run() { + playerLock.lock(); + + if (playerStatus == PlayerStatus.INDETERMINATE) { + setPlayerStatus(PlayerStatus.STOPPED, null); + } else { + if (BuildConfig.DEBUG) Log.d(TAG, "Ignored call to stop: Current player state is: " + playerStatus); + } + playerLock.unlock(); + + } + }); + } + /** * Holds information about a PSMP object. */ -- cgit v1.2.3