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
/** | |
* subscriptions data format: | |
* { eventType: { id: callback } } | |
*/ | |
const subscriptions = { } | |
const getNextUniqueId = getIdGenerator() | |
function subscribe(eventType, callback) { | |
const id = getNextUniqueId() |
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
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' |
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
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(); | |
} |
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
<meta-data android:name= "com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME" | |
android:value="yourpackagename.CastOptionsProvider" /> |
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
<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" /> |
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); |
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 class SimpleChromecastConnectionListener implements ChromecastConnectionListener { | |
@Override | |
public void onChromecastConnecting() { | |
Log.d(getClass().getSimpleName(), "onChromecastConnecting"); | |
} | |
@Override | |
public void onChromecastConnected(ChromecastYouTubePlayerContext chromecastYouTubePlayerContext) { | |
Log.d(getClass().getSimpleName(), "onChromecastConnected"); |
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
<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" /> |
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
View customUiView = youTubePlayerView.inflateCustomPlayerUI(R.layout.custom_player_ui); |
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
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(); |
OlderNewer