Skip to content

Helper library for Android developers looking to add YouTube video playback in their applications via the iframe player in WebView

Notifications You must be signed in to change notification settings

jaytj95/youtube-android-player-helper

 
 

Repository files navigation

Youtube-Android-Player-Helper(YTPlayer)

Helper library for Android developers looking to add YouTube video playback in their applications via the iframe player in WebView

Sample Capture

Download

use Gradle:

 repositories {
  jcenter()
}

dependencies {
  compile 'com.jaedongchicken:ytplayer:1.2.0'
}

Or Maven:

<dependency>
  <groupId>com.jaedongchicken</groupId>
  <artifactId>ytplayer</artifactId>
  <version>1.2.0</version>
  <type>pom</type>
</dependency>

How do I use YTPlayer?

You can see more detail from MainActivity.java.

Simple use cases will look something like this:

  • XML
    <com.jaedongchicken.ytplayer.YoutubePlayerView
        android:id="@+id/youtubePlayerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
  • JAVA
        // get id from XML
        YoutubePlayerView youtubePlayerView = (YoutubePlayerView) findViewById(R.id.youtubePlayerView);
       
         // Control values
         // see more # https://developers.google.com/youtube/player_parameters?hl=en
        YTParams params = new YTParams();
        // params.setControls(0); // hide control
        
         // initialize YoutubePlayerCallBackListener with Params and VideoID
        // youtubePlayerView.initialize("WCchr07kLPE", params, new YoutubePlayerView.YouTubeListener())


       // make auto height of youtube. if you want to use 'wrap_content'
        youtubePlayerView.setAutoPlayerHeight(this);
        // initialize YoutubePlayerCallBackListener and VideoID
        youtubePlayerView.initialize("YOUTUBE_ID", new YoutubePlayerView.YouTubeListener() {

            @Override
            public void onReady() {
                // when player is ready.
            }

            @Override
            public void onStateChange(YoutubePlayerView.STATE state) {
                /**
                 * YoutubePlayerView.STATE
                 *
                 * UNSTARTED, ENDED, PLAYING, PAUSED, BUFFERING, CUED, NONE
                 *
                 */
            }

            @Override
            public void onPlaybackQualityChange(String arg) {
            }

            @Override
            public void onPlaybackRateChange(String arg) {
            }

            @Override
            public void onError(String error) {
            }

            @Override
            public void onApiChange(String arg) {
            }

            @Override
            public void onCurrentSecond(double second) {
                // currentTime callback
            }

            @Override
            public void onDuration(double duration) {
                // total duration
            }

            @Override
            public void logs(String log) {
                // javascript debug log. you don't need to use it.
            }
        });


        // psuse video
        youtubePlayerView.pause();
        // play video when it's ready
        youtubePlayerView.play();

Updated

v 1.2.0 - added YTParams class. v 1.1.0 - added setWhiteBackgroundColor() method.

Author

Jaedong Kim - @JackDinealKIM on GitHub, mashiaro@gmail.com

Disclaimer

This is not an official Google product.

License

Copyright 2016 JD Kim

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.

About

Helper library for Android developers looking to add YouTube video playback in their applications via the iframe player in WebView

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 99.7%
  • HTML 0.3%