Skip to content

Commit

Permalink
Add support for devices who doesnt support Google Play Service
Browse files Browse the repository at this point in the history
  • Loading branch information
fegauthier committed Mar 1, 2023
1 parent 2bfa2bd commit 2d50e3b
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
cast_image = view.findViewById(R.id.cast_image);
mediaRouteButton = view.findViewById(R.id.media_route_button);

castContext = CastContext.getSharedInstance(getContext());

castPlayer = new CastPlayer(CastContext.getSharedInstance(context));


if (!chromecast) {
mediaRouteButton.setVisibility(View.GONE);
} else {
castContext = CastContext.getSharedInstance(getContext());
castPlayer = new CastPlayer(CastContext.getSharedInstance(context));
CastButtonFactory.setUpMediaRouteButton(context, mediaRouteButton);

castContext.addCastStateListener(
Expand Down Expand Up @@ -384,7 +384,7 @@ public void onPlayerStateChanged(boolean playWhenReady, int state) {
resizeBtn.setVisibility(View.VISIBLE);

mediaRouteButtonColorWhite(mediaRouteButton);
if (castContext.getCastState() != CastState.NO_DEVICES_AVAILABLE) mediaRouteButton.setVisibility(
if (castContext != null && castContext.getCastState() != CastState.NO_DEVICES_AVAILABLE) mediaRouteButton.setVisibility(
View.VISIBLE
);

Expand Down Expand Up @@ -655,7 +655,7 @@ public void onStart() {
if (Util.SDK_INT >= 24) {
if (styledPlayerView != null) {
// If cast is playing then it doesn't start the local player once get backs from background
if (!castPlayer.isCastSessionAvailable()) {
if (castPlayer != null && !castPlayer.isCastSessionAvailable()) {
initializePlayer();

if (player.getCurrentPosition() != 0) {
Expand Down Expand Up @@ -739,7 +739,9 @@ public void releasePlayer() {
player = null;
showSystemUI();
resetVariables();
castPlayer.release();
if(castPlayer != null) {
castPlayer.release();
}
}
}

Expand Down

0 comments on commit 2d50e3b

Please sign in to comment.