Skip to content

Instantly share code, notes, and snippets.

@PierfrancescoSoffritti
Created February 11, 2019 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PierfrancescoSoffritti/609cf643235681e06b2b033ebca26ba0 to your computer and use it in GitHub Desktop.
Save PierfrancescoSoffritti/609cf643235681e06b2b033ebca26ba0 to your computer and use it in GitHub Desktop.
private int googlePlayServicesAvailabilityRequestCode = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MediaRouteButton mediaRouteButton = findViewById(R.id.media_route_button);
CastButtonFactory.setUpMediaRouteButton(this, mediaRouteButton);
// can't use CastContext until I'm sure the user has GooglePlayServices
PlayServicesUtils.checkGooglePlayServicesAvailability(
this,
googlePlayServicesAvailabilityRequestCode,
this::initChromecast
);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// can't use CastContext until I'm sure the user has GooglePlayServices
if(requestCode == googlePlayServicesAvailabilityRequestCode) {
PlayServicesUtils.checkGooglePlayServicesAvailability(
this,
googlePlayServicesAvailabilityRequestCode,
this::initChromecast
);
}
}
private void initChromecast() {
new ChromecastYouTubePlayerContext(
CastContext.getSharedInstance(this).getSessionManager(),
new SimpleChromecastConnectionListener()
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment