-Added state saving for streams on skip and player exception events.

-Added query for loading saved stream states.
-Modified orphan record removal to no longer consider stream table records.
This commit is contained in:
John Zhen Mo 2018-01-29 14:08:26 -08:00
parent 9b4a07de34
commit d3160eed9d
5 changed files with 75 additions and 13 deletions

View file

@ -581,6 +581,8 @@ public abstract class BasePlayer implements Player.EventListener, PlaybackListen
errorToast = null;
}
savePlaybackState();
switch (error.type) {
case ExoPlaybackException.TYPE_SOURCE:
if (simpleExoPlayer.getCurrentPosition() <
@ -758,6 +760,8 @@ public abstract class BasePlayer implements Player.EventListener, PlaybackListen
if (simpleExoPlayer == null || playQueue == null) return;
if (DEBUG) Log.d(TAG, "onPlayPrevious() called");
savePlaybackState();
/* If current playback has run for PLAY_PREV_ACTIVATION_LIMIT milliseconds, restart current track.
* Also restart the track if the current track is the first in a queue.*/
if (simpleExoPlayer.getCurrentPosition() > PLAY_PREV_ACTIVATION_LIMIT || playQueue.getIndex() == 0) {
@ -772,6 +776,8 @@ public abstract class BasePlayer implements Player.EventListener, PlaybackListen
if (playQueue == null) return;
if (DEBUG) Log.d(TAG, "onPlayNext() called");
savePlaybackState();
playQueue.offsetIndex(+1);
}
@ -833,6 +839,24 @@ public abstract class BasePlayer implements Player.EventListener, PlaybackListen
);
}
protected void savePlaybackState(final StreamInfo info, final long progress) {
if (context == null || info == null || databaseUpdateReactor == null) return;
final Disposable stateSaver = recordManager.saveStreamState(info, progress)
.observeOn(AndroidSchedulers.mainThread())
.onErrorComplete()
.subscribe();
databaseUpdateReactor.add(stateSaver);
}
private void savePlaybackState() {
if (simpleExoPlayer == null || currentInfo == null) return;
if (simpleExoPlayer.getCurrentPosition() > RECOVERY_SKIP_THRESHOLD &&
simpleExoPlayer.getCurrentPosition() <
simpleExoPlayer.getDuration() - RECOVERY_SKIP_THRESHOLD) {
savePlaybackState(currentInfo, simpleExoPlayer.getCurrentPosition());
}
}
/*//////////////////////////////////////////////////////////////////////////
// Getters and Setters
//////////////////////////////////////////////////////////////////////////*/