Giter Club home page Giter Club logo

customuiyoutubeplayer's Introduction

Custom UI YouTube Player

An Android library containing a Fragment extending YouTubePlayerFragment from Google's YouTube Android Player API, allowing you to easily play YouTube videos in your application with a customizable player controls overlay. For API 16+.

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 set their values to the API key(s) you generated.
    • youtubeDebugApiKey
    • youtubeReleaseApiKey
  4. Import the project into Android Studio.
  5. Build and run on a device that has the Youtube app installed.

####Using the Fragment in your own application

  1. Add the repo to your project's build.gradle
allprojects {
   repositories {
      jcenter()
      ...
      maven {
            url 'https://dl.bintray.com/dptsolutions/maven/'
      }
   }
}
  1. Add the dependency to your application's build.gradle
compile 'com.dptsolutions.customuiyoutubeplayer:customuiyoutubeplayer:0.1'
  1. Copy the styles.xml files from the library to your project, rename the theme, and change values as you wish in the defined styles.

  2. Create an instance of the Fragment using CustomUIYouTubePlayerFragment.newInstance(). Parameters

    • youtubeId (required): ID of YouTube video
    • apiKey (required): Your YouTube Player API key
    • themeResourceId (optional): The ID of your custom theme from step 2 to style the player controls
    • enableDebugLogging (optional): Set to true if you want to see the Fragment's debug messages
  3. Add android:configChanges="keyboardHidden|orientation|screenSize" to the <Activity> tag containing the Fragment in your manifest.

  4. Profit!

License

Copyright 2016 Don Phillips

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

customuiyoutubeplayer's People

Contributors

dptsolutions avatar ryancford avatar

Watchers

James Cloos avatar KARTHIK RAMESH avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.