ryancford / YoutubePlayerCustomOverlayExample

Example project to demonstrate how to build a custom player UI that overlays a fullscreen YoutubePlayerFragment from Google's YouTube Android Player API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

YoutubePlayerCustomOverlayExample

Example project to demonstrate how to build a custom video player UI that overlays a YouTubePlayerFragment from Google's YouTube Android Player API.

Why is this interesting?

While the API allows for you to implement custom controls for the YouTubePlayer, and provides an example for this in the the demo app, there is one big thing that they neglect to call out in the example - you cannot draw a view on top of a YouTubePlayerView. If you try, the player will stop playback as soon as the view is drawn on top of the player, and will throw an YouTubePlayerView.ErrorReason.UNAUTHORIZED_OVERLAY error. Thus, on the surface it appears that you cannot make your own custom UI for the player that functions like most video players on Android, where the controls overlay the fullscreen video, and are show or hidden when the user taps the screen.

Fortunately, you can get around this "feature" by using a PopupWindow to contain the controls that will be drawn on top of the YouTubePlayerView. A PopupWindow doesn't seem to trigger the error.

##Cool, so how do I use this?

####Running the demo app

  1. Follow the instructions to generate API keys (using both the debug and release keystores) for Android apps at the Google Developer Console.
  2. Clone the repo.
  3. Create a gradle.properties file in the root of the project, add the following properties, and initially set their values to the API key(s) you generated.
  • youtubeDebugApiKey
  • youtubeReleaseApiKey
  1. Import the project into Android Studio.
  2. Build and run on a device that has the Youtube app installed.

####Using the code in your own application Basically, just copy the YouTubePlayerActivity in the app to your own app, and all it's related resources. Then style it however you wish.

The YouTubePlayerActivity expects your Google API key for the YouTubePlayer to be located in the BuildConfig.GOOGLE_API_KEY field, and the build script expects the values for the key to be found in your gradle.properties file. See the build.gradle for the app for details.

##Anything I need to watch out for?

  • Currently, the YouTubePlayerActivity crashes on orientation change. So lock it to landscape in your manifest. (Fixing this is on the TODO list)
  • The cueVideo() method to load a video seems buggy and not always work. Stick with loadVideo().

About

Example project to demonstrate how to build a custom player UI that overlays a fullscreen YoutubePlayerFragment from Google's YouTube Android Player API

License:Apache License 2.0


Languages

Language:Java 100.0%