Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

Commit

Permalink
Fixed an issue where playback was stopped incorrectly..
Browse files Browse the repository at this point in the history
CastManager.onSessionDisconnected() was being called occasionally when switching back to the app, replacing the Playback with a new instance of MediaPlayerPlayback(), despite the fact that we weren't using Chromecast, so the playback didn't need replacing. This resulted in an unnecessary call to Playback.stop().
  • Loading branch information
timusus committed Dec 2, 2018
1 parent 0f4e98d commit 8173f69
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.google.android.gms.cast.framework.CastSession;
import com.google.android.gms.cast.framework.SessionManager;
import com.google.android.gms.cast.framework.SessionManagerListener;
import com.simplecity.amp_library.ShuttleApplication;
import com.simplecity.amp_library.playback.CastPlayback;
import com.simplecity.amp_library.playback.MediaPlayerPlayback;
import com.simplecity.amp_library.playback.Playback;
Expand Down Expand Up @@ -65,12 +64,15 @@ public void onSessionStartFailed(CastSession castSession, int i) {
public void onSessionEnding(CastSession castSession) {
Log.d(TAG, "onSessionEnding.. isPlaying" + playbackManager.isPlaying());

// This is our final chance to update the underlying stream position In onSessionEnded(), the underlying CastPlayback#mRemoteMediaClient
// is disconnected and hence we update our local value of stream position to the latest position.
playbackManager.getPlayback().updateLastKnownStreamPosition();
if (playbackManager.getPlayback() instanceof CastPlayback) {

Playback playback = new MediaPlayerPlayback(applicationContext);
playbackManager.switchToPlayback(playback, playbackManager.getPlayback().getPosition());
// This is our final chance to update the underlying stream position In onSessionEnded(), the underlying CastPlayback#mRemoteMediaClient
// is disconnected and hence we update our local value of stream position to the latest position.
playbackManager.getPlayback().updateLastKnownStreamPosition();

Playback playback = new MediaPlayerPlayback(applicationContext);
playbackManager.switchToPlayback(playback, playbackManager.getPlayback().getPosition());
}
}

@Override
Expand Down

0 comments on commit 8173f69

Please sign in to comment.