Skip to content

Instantly share code, notes, and snippets.

class CustomUiController {
private boolean isPlaying = false;
CustomUiController(View customPlayerUI, YouTubePlayer youTubePlayer) {
playPauseButton = customPlayerUI.findViewById(R.id.play_pause_button);
playPauseButton.setOnClickListener( view -> {
if(isPlaying) youTubePlayer.pause();
else youTubePlayer.play();
View customUiView = youTubePlayerView.inflateCustomPlayerUI(R.layout.custom_player_ui);
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/play_pause_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play/Pause" />
implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:chromecast-sender:last-version'
// this is not needed to use the library, but it provides the very useful MediaRouteButton.
implementation 'androidx.mediarouter:mediarouter:last-version'
private class SimpleChromecastConnectionListener implements ChromecastConnectionListener {
@Override
public void onChromecastConnecting() {
Log.d(getClass().getSimpleName(), "onChromecastConnecting");
}
@Override
public void onChromecastConnected(ChromecastYouTubePlayerContext chromecastYouTubePlayerContext) {
Log.d(getClass().getSimpleName(), "onChromecastConnected");
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);
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.app.MediaRouteButton
android:id="@+id/media_route_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<meta-data android:name= "com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
android:value="yourpackagename.CastOptionsProvider" />
public final class CastOptionsProvider implements OptionsProvider {
public CastOptions getCastOptions(Context appContext) {
// Register your receiver on Cast Developer Console to get this ID: https://cast.google.com/publish
String receiverId = "";
return new CastOptions.Builder()
.setReceiverApplicationId(receiverId)
.build();
}