Created
February 11, 2019 16:55
-
-
Save PierfrancescoSoffritti/609cf643235681e06b2b033ebca26ba0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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