Skip to content

Commit

Permalink
updates documentation and sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
PierfrancescoSoffritti committed Feb 10, 2019
1 parent f49d0f7 commit c364628
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 23 deletions.
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ YouTube added some non-removable buttons to the IFrame Player, as mentioned in [

Read the documentation of the [`initializeWithWebUi`](#initializeWithWebUi(YouTubePlayerListener,-boolean)) method to learn more about the effects of this attribute.

Web UI screenshot:
*Web UI screenshot:*

![web-ui screenshot](./images/web_based_ui_screenshot.jpg)

Expand All @@ -286,6 +286,10 @@ This attribute expects a `boolean`. Its default value is `false`.

This attribute does nothing if `useWebUi` is `true`.

*Live UI screenshot:*

![live-ui screenshot](./images/live_ui_screenshot.jpg)

#### showYouTubeButton
This attribute expects a `boolean`. Its default value is `true`.

Expand Down Expand Up @@ -644,6 +648,10 @@ Unfortunately there is no way for the player to automatically know if it is play

You can obtain the same result by setting the xml attribute `app:enableLiveVideoUi="true"` of `YouTubePlayerView`.

*Live-ui screenshot:*

![live-ui screenshot](./images/live_ui_screenshot.jpg)

### Custom actions
You can set custom actions on the right and left side of the Play/Pause button of the player

Expand All @@ -653,6 +661,9 @@ PlayerUiController.setCustomAction2(Drawable icon, OnClickListener listener);
PlayerUiController.showCustomAction1(boolean show);
PlayerUiController.showCustomAction2(boolean show);
```
*Custom actions example:*

![custom actions screenshot](./images/custom_actions_screenshot.jpg)

You can **also add any type of View to the UI**, this can be useful if you want to add a new icon.

Expand All @@ -663,10 +674,14 @@ PlayerUiController.removeView(View view);

The View will be added to the top corner of the player.

*Example of views added to the player (see Chromecast icon in the top-right corner):*

![custom actions screenshot](./images/chromecast_screenshot.jpg)

## Create your own custom UI
Customization is an important aspect of this library. If need to, you can completely replace the default UI of the player.

`YouTubePlayerView` has method for that.
`YouTubePlayerView` has method for that.

```java
View inflateCustomPlayerUi(@LayoutRes int customUiLayoutID)
Expand Down Expand Up @@ -697,7 +712,7 @@ youTubePlayerView.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
```
A blog post going deeper on this is available [at this link](https://medium.com/@soffritti.pierfrancesco/customize-android-youtube-players-ui-9f32da9e8505).

Example of an (ugly) custom UI:
*Example of a custom UI: (this is just a ugly example, but here your design skills are the limit :))*

![Sample app example](https://media.giphy.com/media/SradsoNdy1DNVGHGy5/giphy.gif)

Expand Down Expand Up @@ -798,6 +813,10 @@ By default the menu icon is not visible.

The default `OnClickListener` opens the menu when the menu icon is clicked. You can change this behaviour, for example to open a menu with a different UX, like a bottom sheet panel. Obviously if you want a UX different from the one provided by the library, you are responsible for creating your own components.

*Menu screenshot:*

![menu screenshot](./images/menu_screenshot.jpg)

### YouTubePlayerMenu
You can get a reference of the `YouTubePlayerMenu` from the `PlayerUiController`.
```java
Expand Down Expand Up @@ -854,10 +873,14 @@ The minSdk of the library is 17. [At this point in time](https://developer.andro
I'm not sure how WebView will behave on older versions of Android, but technically it should be possible to lower the minSdk. If you absolutely need to support older devices, I suggest you fork the library and lower the minSdk yourself.

### How to disable share and watch later buttons
YouTube made some changes to the IFrame player, unfortunately it's not possible to hide those buttons.
YouTube made some changes to the IFrame player, unfortunately it's not possible to remove those buttons.

If you want to be able to click them, you should [use the web-based UI](#web-based-ui) of the player instead of the native UI.

*Watch later and share button are in the top right corner, they are visible when the ui is visible:*

![web-ui screenshot](./images/web_based_ui_screenshot.jpg)

---

# Chromecast extension library
Expand Down Expand Up @@ -1019,7 +1042,11 @@ You can call `loadVideo`, `cueVideo`, `pause`, `play` etc.. on the `YouTubePlaye

For how to use the `YouTubePlayer` object and `YouTubePlayerListener`, you can refer to the documentation for the *core* library, [YouTubePlayer](#youtubeplayer).

This example can also be found [in the sample app](#./chromecast-sender-sample-app/src/main/java/com/pierfrancescosoffritti/cyplayersample/examples/basicExample/BasicExampleActivity.kt), written in Kotlin.
This example can be found [in the chromecast-sender sample app](./chromecast-sender-sample-app/src/main/java/com/pierfrancescosoffritti/cyplayersample/examples/basicExample/BasicExampleActivity.kt), written in Kotlin and in the [core sample app](./core-sample-app/src/main/java/com/pierfrancescosoffritti/aytplayersample/examples/chromecastExample/), wirtten in Java.

*Screenshot of the CastButton added to the YouTubePlayerView:*

![chromecast button screenshot](./images/chromecast_screenshot.jpg)

### Receiver
This library requires a custom receiver, you can find the source code of the *chromecast-receiver* [here](./chromecast-receiver).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void onReady(@NonNull YouTubePlayer youTubePlayer) {
0f
);

addFullScreenListenerToPlayer(youTubePlayer);
addFullScreenListenerToPlayer();
setPlayNextVideoButtonClickListener(youTubePlayer);
}
});
Expand All @@ -100,22 +100,22 @@ private void initPlayerMenu() {
view -> Toast.makeText(this, "item no icon clicked", Toast.LENGTH_SHORT).show()));
}

private void addFullScreenListenerToPlayer(final YouTubePlayer youTubePlayer) {
private void addFullScreenListenerToPlayer() {
youTubePlayerView.addFullScreenListener(new YouTubePlayerFullScreenListener() {
@Override
public void onYouTubePlayerEnterFullScreen() {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
fullScreenHelper.enterFullScreen();

addCustomActionToPlayer();
addCustomActionsToPlayer();
}

@Override
public void onYouTubePlayerExitFullScreen() {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
fullScreenHelper.exitFullScreen();

removeCustomActionFromPlayer();
removeCustomActionsFromPlayer();
}
});
}
Expand All @@ -124,16 +124,22 @@ public void onYouTubePlayerExitFullScreen() {
* This method adds a new custom action to the player.
* Custom actions are shown next to the Play/Pause button in the middle of the player.
*/
private void addCustomActionToPlayer() {
Drawable customActionIcon = ContextCompat.getDrawable(this, R.drawable.ic_mood_white_32dp);
assert customActionIcon != null;
private void addCustomActionsToPlayer() {
Drawable customAction1Icon = ContextCompat.getDrawable(this, R.drawable.ic_fast_rewind_white_24dp);
Drawable customAction2Icon = ContextCompat.getDrawable(this, R.drawable.ic_fast_forward_white_24dp);
assert customAction1Icon != null;
assert customAction2Icon != null;

youTubePlayerView.getPlayerUiController().setCustomAction1(customActionIcon, view ->
youTubePlayerView.getPlayerUiController().setCustomAction1(customAction1Icon, view ->
Toast.makeText(this, "custom action1 clicked", Toast.LENGTH_SHORT).show());

youTubePlayerView.getPlayerUiController().setCustomAction2(customAction2Icon, view ->
Toast.makeText(this, "custom action1 clicked", Toast.LENGTH_SHORT).show());
}

private void removeCustomActionFromPlayer() {
private void removeCustomActionsFromPlayer() {
youTubePlayerView.getPlayerUiController().showCustomAction1(false);
youTubePlayerView.getPlayerUiController().showCustomAction2(false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M4,18l8.5,-6L4,6v12zM13,6v12l8.5,-6L13,6z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M11,18L11,6l-8.5,6 8.5,6zM11.5,12l8.5,6L20,6l-8.5,6z"/>
</vector>
9 changes: 0 additions & 9 deletions core-sample-app/src/main/res/drawable/ic_mood_white_32dp.xml

This file was deleted.

Binary file added images/chromecast_screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/custom_actions_screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/live_ui_screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/menu_screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c364628

Please sign in to comment.