Code Monkey home page Code Monkey logo

youtube-android-player-helper's Introduction

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.4.4'
}

Or Maven:

<dependency>
  <groupId>com.jaedongchicken</groupId>
  <artifactId>ytplayer</artifactId>
  <version>1.4.4</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
        // params.setVolume(100); // volume control
        // params.setPlaybackQuality(PlaybackQuality.small); // video quality control

        
         // initialize YoutubePlayerCallBackListener with Params and VideoID
        // youtubePlayerView.initialize("WCchr07kLPE", params, new YoutubePlayerView.YouTubeListener())

		// initialize YoutubePlayerCallBackListener with Params and Full Video URL
        // To Use - avoid UMG block!!!! but you'd better make own your server for your real service.
        // youtubePlayerView.initializeWithCustomURL("p1Zt47V3pPw" or "http://jaedong.net/youtube/p1Zt47V3pPw", 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();
        
    
    @Override
    protected void onPause() {
        super.onPause();
        // pause video when on the background mode.
        youtubePlayerView.pause();
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
        // this is optional but you need.
        youtubePlayerView.destroy();
    }
    

Updated

V 1.4.4 - Open Player when you click the logo.
V 1.4.3 - Fixed player is not to redirect.
v 1.4.2 - fix handler.
v 1.4.1 - Solved UMG block.
v 1.3.0 - added AudioVolume, VideoQualoty in YTParams class.
v 1.2.0 - added YTParams class, many youtube functions defined.
v 1.1.0 - added setWhiteBackgroundColor() method.

Author

Jaedong Kim - @JackDinealKIM on GitHub, [email protected]

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.

youtube-android-player-helper's People

Contributors

jackdinealkim avatar jaytj95 avatar jd-qualson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

youtube-android-player-helper's Issues

AutoPlay not work

YTParams params = new YTParams(); params.setControls(1); params.setAutoplay(1); params.setVolume(100);
its my code . How can I do to let it auto play the video ?

Video not playing automatically

On devices below Android 5, Lollipop video doesn't start automatically.
I have used .play() method i onReady() method.
And I'm getting following error:
A WebView method was called on a thread 'JavaBridge'. All WebView methods must be called on the same thread
which could easily solved by method runOnUiThread method.

wanna disable or hide watch later button

hey! thanks a lot to such an amazing work. Can you please tell is there a way or method to disable or hide controls like watch later etc.? Thank you.
Your response would be highly appreciated.

Android 4.1.2 not working

Hi,

Testing in Android 4.1.2 seems not working, only the audio is loaded but the image don't. Is there a minimum Android version to work?

Thanks for your work

seekToMillis is not working.

I want to seek video to a specific millisecond but seekToMillis() function is not working. When I called this function , state of YoutubeView changes to ENDED.

FullScreen option

Hi, is there any way to show a full screen option in the player?

Thanks you very much.

FS parameter missing

Is there any reason not to include 'fs' param to allow fullscreen video? It seems like the default is showing fullscreen but I don't see it in video iframe.

setAutoPlayerHeight does not change height dynamically

Hi, thanks for the library.
I'm using the .setAutoPlayerHeight to wrap the content, it worked once the activity started. But when the activity changed orientation, the height doesn't change dynamically and i guess it retained the first measured height. Is there any workaround for this?
And also, .setWhiteBackgroundColor doesn't seem to work on me.

Google Policy

Impossible to publish new app because it violates their device and network abuse policy and section 4.4 of their Developer Distribution Agreement.

Now, you can't pllay youtube video in background without using Youtube API

Any solution ?

First Time .play(); not working.

Now when first time load video and after OnReady, youtubePlayerView.play(); not working, please solve this if possible.

Thank You.

ActivityNotFoundException

Hey, thanks for the library.
I'm facing this issue when I try to start the activity.

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.application.example/com.jaedongchicken.ytplayer.YoutubePlayerView}; have you declared this activity in your AndroidManifest.xml?

Do you know how can I fix this issue?

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.