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="remove_from_queue_label">Remove from Queue</string>
|
||||||
<string name="player_ready_msg">Ready</string>
|
<string name="player_ready_msg">Ready</string>
|
||||||
<string name="stream_label">Stream</string>
|
<string name="stream_label">Stream</string>
|
||||||
|
<string name="player_seeking_msg">Seeking</string>
|
||||||
|
<string name="player_playing_msg"></string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -140,7 +140,7 @@ public class MediaplayerActivity extends SherlockActivity {
|
||||||
butPlay.setImageResource(android.R.drawable.ic_media_play);
|
butPlay.setImageResource(android.R.drawable.ic_media_play);
|
||||||
break;
|
break;
|
||||||
case PLAYING:
|
case PLAYING:
|
||||||
setStatusMsg(0, View.INVISIBLE);
|
setStatusMsg(R.string.player_playing_msg, View.INVISIBLE);
|
||||||
loadMediaInfo();
|
loadMediaInfo();
|
||||||
setupPositionObserver();
|
setupPositionObserver();
|
||||||
butPlay.setImageResource(android.R.drawable.ic_media_pause);
|
butPlay.setImageResource(android.R.drawable.ic_media_pause);
|
||||||
|
@ -156,6 +156,9 @@ public class MediaplayerActivity extends SherlockActivity {
|
||||||
loadMediaInfo();
|
loadMediaInfo();
|
||||||
setStatusMsg(R.string.player_ready_msg, View.VISIBLE);
|
setStatusMsg(R.string.player_ready_msg, View.VISIBLE);
|
||||||
butPlay.setImageResource(android.R.drawable.ic_media_play);
|
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 PlayerStatus status;
|
||||||
private PositionSaver positionSaver;
|
private PositionSaver positionSaver;
|
||||||
|
|
||||||
|
private PlayerStatus statusBeforeSeek;
|
||||||
|
|
||||||
private final IBinder mBinder = new LocalBinder();
|
private final IBinder mBinder = new LocalBinder();
|
||||||
|
|
||||||
public class LocalBinder extends Binder {
|
public class LocalBinder extends Binder {
|
||||||
|
@ -93,6 +95,7 @@ public class PlaybackService extends Service {
|
||||||
player = new MediaPlayer();
|
player = new MediaPlayer();
|
||||||
player.setOnPreparedListener(preparedListener);
|
player.setOnPreparedListener(preparedListener);
|
||||||
player.setOnCompletionListener(completionListener);
|
player.setOnCompletionListener(completionListener);
|
||||||
|
player.setOnSeekCompleteListener(onSeekCompleteListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -219,13 +222,25 @@ public class PlaybackService extends Service {
|
||||||
@Override
|
@Override
|
||||||
public void onPrepared(MediaPlayer mp) {
|
public void onPrepared(MediaPlayer mp) {
|
||||||
Log.d(TAG, "Resource prepared");
|
Log.d(TAG, "Resource prepared");
|
||||||
|
mp.seekTo(media.getPosition());
|
||||||
setStatus(PlayerStatus.PREPARED);
|
setStatus(PlayerStatus.PREPARED);
|
||||||
if (startWhenPrepared) {
|
if (startWhenPrepared) {
|
||||||
play();
|
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() {
|
private MediaPlayer.OnCompletionListener completionListener = new MediaPlayer.OnCompletionListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -318,6 +333,10 @@ public class PlaybackService extends Service {
|
||||||
|
|
||||||
public void seek(int i) {
|
public void seek(int i) {
|
||||||
Log.d(TAG, "Seeking position " + i);
|
Log.d(TAG, "Seeking position " + i);
|
||||||
|
if (shouldStream) {
|
||||||
|
statusBeforeSeek = status;
|
||||||
|
setStatus(PlayerStatus.SEEKING);
|
||||||
|
}
|
||||||
player.seekTo(i);
|
player.seekTo(i);
|
||||||
saveCurrentPosition();
|
saveCurrentPosition();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
package de.podfetcher.service;
|
package de.podfetcher.service;
|
||||||
|
|
||||||
public enum PlayerStatus {
|
public enum PlayerStatus {
|
||||||
ERROR, PREPARING, PAUSED, PLAYING, STOPPED, PREPARED
|
ERROR, PREPARING, PAUSED, PLAYING, STOPPED, PREPARED, SEEKING
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue