diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2012-06-22 14:19:40 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2012-06-22 14:19:40 +0200 |
commit | 426df3f49f4c2a6f7b2a5dd44fb84c5240ebc87e (patch) | |
tree | 39b7cf956007ecf40fa77ef87925ef9f59717320 /src/de/podfetcher | |
parent | eee5c43bf00d76cac9e74273ed96c61974e1b088 (diff) | |
download | AntennaPod-426df3f49f4c2a6f7b2a5dd44fb84c5240ebc87e.zip |
Improved seeking mechanism for streams
Diffstat (limited to 'src/de/podfetcher')
-rw-r--r-- | src/de/podfetcher/activity/MediaplayerActivity.java | 5 | ||||
-rw-r--r-- | src/de/podfetcher/service/PlaybackService.java | 21 | ||||
-rw-r--r-- | src/de/podfetcher/service/PlayerStatus.java | 2 |
3 files changed, 25 insertions, 3 deletions
diff --git a/src/de/podfetcher/activity/MediaplayerActivity.java b/src/de/podfetcher/activity/MediaplayerActivity.java index f5aaab455..4b6e07419 100644 --- a/src/de/podfetcher/activity/MediaplayerActivity.java +++ b/src/de/podfetcher/activity/MediaplayerActivity.java @@ -140,7 +140,7 @@ public class MediaplayerActivity extends SherlockActivity { butPlay.setImageResource(android.R.drawable.ic_media_play); break; case PLAYING: - setStatusMsg(0, View.INVISIBLE); + setStatusMsg(R.string.player_playing_msg, View.INVISIBLE); loadMediaInfo(); setupPositionObserver(); butPlay.setImageResource(android.R.drawable.ic_media_pause); @@ -156,6 +156,9 @@ public class MediaplayerActivity extends SherlockActivity { loadMediaInfo(); setStatusMsg(R.string.player_ready_msg, View.VISIBLE); butPlay.setImageResource(android.R.drawable.ic_media_play); + break; + case SEEKING: + setStatusMsg(R.string.player_seeking_msg, View.VISIBLE); } } diff --git a/src/de/podfetcher/service/PlaybackService.java b/src/de/podfetcher/service/PlaybackService.java index 13238357f..412e84198 100644 --- a/src/de/podfetcher/service/PlaybackService.java +++ b/src/de/podfetcher/service/PlaybackService.java @@ -74,6 +74,8 @@ public class PlaybackService extends Service { private PlayerStatus status; private PositionSaver positionSaver; + private PlayerStatus statusBeforeSeek; + private final IBinder mBinder = new LocalBinder(); public class LocalBinder extends Binder { @@ -93,6 +95,7 @@ public class PlaybackService extends Service { player = new MediaPlayer(); player.setOnPreparedListener(preparedListener); player.setOnCompletionListener(completionListener); + player.setOnSeekCompleteListener(onSeekCompleteListener); } @Override @@ -219,13 +222,25 @@ public class PlaybackService extends Service { @Override public void onPrepared(MediaPlayer mp) { Log.d(TAG, "Resource prepared"); + mp.seekTo(media.getPosition()); setStatus(PlayerStatus.PREPARED); if (startWhenPrepared) { play(); } } }; - + + private MediaPlayer.OnSeekCompleteListener onSeekCompleteListener = new MediaPlayer.OnSeekCompleteListener() { + + @Override + public void onSeekComplete(MediaPlayer mp) { + if (status == PlayerStatus.SEEKING) { + setStatus(statusBeforeSeek); + } + + } + }; + private MediaPlayer.OnCompletionListener completionListener = new MediaPlayer.OnCompletionListener() { @Override @@ -318,6 +333,10 @@ public class PlaybackService extends Service { public void seek(int i) { Log.d(TAG, "Seeking position " + i); + if (shouldStream) { + statusBeforeSeek = status; + setStatus(PlayerStatus.SEEKING); + } player.seekTo(i); saveCurrentPosition(); } diff --git a/src/de/podfetcher/service/PlayerStatus.java b/src/de/podfetcher/service/PlayerStatus.java index 0587bb14e..2c44a27b2 100644 --- a/src/de/podfetcher/service/PlayerStatus.java +++ b/src/de/podfetcher/service/PlayerStatus.java @@ -1,5 +1,5 @@ package de.podfetcher.service; public enum PlayerStatus { - ERROR, PREPARING, PAUSED, PLAYING, STOPPED, PREPARED + ERROR, PREPARING, PAUSED, PLAYING, STOPPED, PREPARED, SEEKING } |