GithubHelp home page GithubHelp logo

firozanawar / android-youtube-player Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pierfrancescosoffritti/android-youtube-player

7.0 5.0 4.0 22.23 MB

YouTube Player library for Android, stable and customizable.

Home Page: https://pierfrancescosoffritti.github.io/Android-YouTube-Player/

License: MIT License

Java 93.95% HTML 6.05%

android-youtube-player's Introduction

Android-YouTube-Player

The Android-YouTube-Player library is a stable and customizable open source YouTube player for Android. It provides a simple View that can be easily integrated in every Activity/Fragment.

The interaction with YouTube is based on the IFrame Player API, running inside of a WebView, therefore the YouTube app is not required to be installed on the user's device.

The web UI of the IFrame Player player is hidden, instead a native UI built on top of Android is used to interact with the player, providing a native experience to the users.

Why does this library exists?

This library has been developed out of necessity. The official library provided by Google to integrate YouTube videos in Android apps is the YouTube Android Player API. I've found the official library to be quite buggy (some bugs are 5+ years old) and lacking in terms of support from Google. It was quite unreliable and unusable in production.

A lengthier explanation to why you may want to consider using an alternative to the official YouTube player is written in this Medium post.


This library has a Wiki, check it out!

A list of published apps that are using this library: (let me know if you want to add your app to this list)

Download

Add this to your project-level build.gradle:

allprojects {
  repositories {
    ...
    maven { url "https://jitpack.io" }
  }
}

Add this to your module-level build.gradle:

dependencies {
  implementation 'com.github.PierfrancescoSoffritti:AndroidYouTubePlayer:7.0.1'
}

Proguard

If you are using ProGuard you might need to add the following options:

-keep public class com.pierfrancescosoffritti.youtubeplayer.** {
   public *;
}

-keepnames class com.pierfrancescosoffritti.youtubeplayer.*

Usage

A sample project that shows how to use the library is available in the sample module. You can also download the sample apk here, or on the PlayStore.

Get it on Google Play

Please refer to the Wiki of the library for a detailed description on how to use it.

Quick start

In order to start using the player you need to add the YouTubePlayerView to your layout

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.pierfrancescosoffritti.youtubeplayer.player.YouTubePlayerView
        android:id="@+id/youtube_player_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

Get a reference to the YouTubePlayerView in your code and initialize it

YouTubePlayerView youTubePlayerView = findViewById(R.id.youtube_player_view);

youTubePlayerView.initialize(new YouTubePlayerInitListener() {
    @Override
    public void onInitSuccess(final YouTubePlayer initializedYouTubePlayer) {    
        initializedYouTubePlayer.addListener(new AbstractYouTubePlayerListener() {
            @Override
            public void onReady() {
                String videoId = "6JYIGclVQdw";
                initializedYouTubePlayer.loadVideo(videoId, 0);
            }
        });        
    }
}, true);

More info on the initialization method can be found here.

The AbstractYouTubePlayerListener is just a convenience abstract class that implements YouTubePlayerListener, so that is not necessary to always implement all the methods of the interface.

The playback of the videos is handled by the YouTubePlayer. You must use that for everything concerning video playback.

Customize player UI

The UI of the player is handled by a PlayerUIController, in order to interact with it you must get its reference from the YouTubePlayerView

PlayerUIController uiController = youTubePlayerView.getPlayerUIController();

You can use the PlayerUIController to customize the UI of the player. You can show or hide Views in it, add your own Views and icons, remap click listeners etc. Read more about it here.

If you need even more control over the UI and you want to design it specifically for your app, you have the freedom to do it. You can completly replace the default UI with your own. Simply call the method View YouTubePlayerView.inflateCustomPlayerUI(@LayoutRes int customPlayerUILayoutID).

This method takes in the id of a layout resource. The method returns the View object corresponding to the inflated layout. The default UI of the player gets removed and replaced with the new UI, giving you all the freedom you want. You can read more in the Wiki and in this blog post.

android-youtube-player's People

Contributors

askarsyzdykov avatar denino avatar pierfrancescosoffritti avatar talklittle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  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.