Improved seeking mechanism for streams
This commit is contained in:
parent
eee5c43bf0
commit
426df3f49f
|
@ -53,4 +53,6 @@
|
|||
<string name="remove_from_queue_label">Remove from Queue</string>
|
||||
<string name="player_ready_msg">Ready</string>
|
||||
<string name="stream_label">Stream</string>
|
||||
<string name="player_seeking_msg">Seeking</string>
|
||||
<string name="player_playing_msg"></string>
|
||||
</resources>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,6 +222,7 @@ 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();
|
||||
|
@ -226,6 +230,17 @@ public class PlaybackService extends Service {
|
|||
}
|
||||
};
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package de.podfetcher.service;
|
||||
|
||||
public enum PlayerStatus {
|
||||
ERROR, PREPARING, PAUSED, PLAYING, STOPPED, PREPARED
|
||||
ERROR, PREPARING, PAUSED, PLAYING, STOPPED, PREPARED, SEEKING
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue