From 426df3f49f4c2a6f7b2a5dd44fb84c5240ebc87e Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Fri, 22 Jun 2012 14:19:40 +0200 Subject: Improved seeking mechanism for streams --- src/de/podfetcher/activity/MediaplayerActivity.java | 5 ++++- src/de/podfetcher/service/PlaybackService.java | 21 ++++++++++++++++++++- src/de/podfetcher/service/PlayerStatus.java | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) (limited to 'src/de/podfetcher') 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 } -- cgit v1.2.3