Skip to content

Commit

Permalink
bug fix: add "RELEASED_ALL_BUT_CAST_SESSION" mode
Browse files Browse the repository at this point in the history
issue this solves:
==================
* in "BrowserActivity":
  * select video URL(s) to watch
* in "VideoActivity":
  * start a cast session
  * playlist of video URLs appears on screen
  * when a video in playlist is clicked:
    * video queue loads in Chromecast
    * position in queue skips to selected playlist item
  * "onPause" runs when Activity screen is closed
    * "PlayerManager" enters "CAST_ONLY" mode and releases all other resources
* in "BrowserActivity":
  * select video URL(s) to watch
* in "VideoActivity":
  * "onResume" runs and detects that "PlayerManager" is running in "CAST_ONLY" mode
    * previously:
      * "PlayerManager" transitioned: "CAST_ONLY" -> "RELEASED" -> "NORMAL"
      * "RELEASED" mode releases all resources, including closing the CastSession
      * "currentPlayer" is an instance of ExoPlayer
    * now:
      * "PlayerManager" transitions: "CAST_ONLY" -> "RELEASED_ALL_BUT_CAST_SESSION" -> "NORMAL"
      * "RELEASED_ALL_BUT_CAST_SESSION" mode is identical to "RELEASED", but CastSession is not closed
      * "currentPlayer" is an instance of CastPlayer
        * the previous video queue that was casting continues uninterupted
        * the new playlist of video URLs appears on screen
        * when a video in playlist is clicked:
          * new video queue loads in Chromecast
          * position in new queue skips to selected playlist item
  • Loading branch information
warren-bank committed May 17, 2019
1 parent 2bece81 commit 56c1835
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public interface QueuePositionListener {
private boolean castMediaQueueCreationPending;
private Player currentPlayer;

public static enum PlaybackMode { NORMAL, CAST_ONLY, RELEASED }
public static enum PlaybackMode { NORMAL, CAST_ONLY, RELEASED_ALL_BUT_CAST_SESSION, RELEASED }

private PlaybackMode playbackMode;

Expand Down Expand Up @@ -263,12 +263,18 @@ public void setPlaybackMode(PlaybackMode playbackMode) {
release_exoPlayer();
}
else {
release();
release(false);
playbackMode = PlaybackMode.RELEASED;
}
break;
case RELEASED_ALL_BUT_CAST_SESSION:
release(
isCasting()
);
playbackMode = PlaybackMode.RELEASED;
break;
case RELEASED:
release();
release(false);
break;
default:
return;
Expand All @@ -295,11 +301,15 @@ public boolean dispatchKeyEvent(KeyEvent event) {
* Releases the manager and the players that it holds.
*/
private void release() {
release(false);
}

private void release(boolean retain_CastSession) {
if (playbackMode == PlaybackMode.RELEASED) return;

try {
release_exoPlayer();
release_castPlayer();
release_castPlayer(retain_CastSession);

mediaQueue.clear();
concatenatingMediaSource.clear();
Expand Down Expand Up @@ -332,14 +342,17 @@ private void release_exoPlayer() {
catch (Exception e){}
}

private void release_castPlayer() {
private void release_castPlayer(boolean retain_CastSession) {
if (castPlayer == null) return;

try {
castControlView.setPlayer(null);
castPlayer.removeListener(this);
castPlayer.setSessionAvailabilityListener(null);
castPlayer.release();

if (!retain_CastSession) {
castPlayer.release();
}

castControlView = null;
castPlayer = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
import java.util.ArrayList;

public class VideoActivity extends AppCompatActivity implements PlayerManager.QueuePositionListener {
private static PlayerManager playerManager = null;

private PlayerView localPlayerView;
private PlayerControlView castControlView;
private PlayerManager playerManager;
private RecyclerView mediaQueueList;
private MediaQueueListAdapter mediaQueueListAdapter;
private CastContext castContext;
Expand Down Expand Up @@ -111,7 +111,7 @@ public void onResume() {
}

if ((playerManager != null) && (playerManager.getPlaybackMode() == PlayerManager.PlaybackMode.CAST_ONLY)) {
playerManager.setPlaybackMode(PlayerManager.PlaybackMode.RELEASED);
playerManager.setPlaybackMode(PlayerManager.PlaybackMode.RELEASED_ALL_BUT_CAST_SESSION);
playerManager = null;
}

Expand Down
4 changes: 2 additions & 2 deletions constants.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project.ext {
releaseVersionCode = 004030416
releaseVersion = '004.03.04-16API'
releaseVersionCode = 004040016
releaseVersion = '004.04.00-16API'
minSdkVersion = 16
targetSdkVersion = 28
compileSdkVersion = 28
Expand Down

0 comments on commit 56c1835

Please sign in to comment.