Giter VIP home page Giter VIP logo

androidyoutubeplayer's Introduction

AndroidYouTubePlayer

Android Arsenal

The AndroidYouTubePlayer is a simple View that can be easily integrated in every Activity/Fragment. The interaction with YouTube is based on the IFrame Player API, therefore the YouTube app is not required to use the player.

This library has been developed out of necessity. At the time I was working on an app completely based on the fruition of YouTube videos. There's an official API provided by Google for the integration of YouTube videos in an Android app: the YouTube Android Player API. But its many bugs and the total lack of support from Google made it impossible to use in production. The app was crashing because of internal bugs of the player (with 3 years old bug reports) and no update has been released in almost a year.

So here it is, the AndroidYouTubePlayer.

Download the sample app here

Apps using this library: Shuffly

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 {
  compile 'com.github.PierfrancescoSoffritti:AndroidYouTubePlayer:0.7.2'
}

Proguard

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

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

-keepnames class com.pierfrancescosoffritti.youtubeplayer.*

Usage

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.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 = (YouTubePlayerView) findViewById(R.id.youtube_player_view);
youTubePlayerView.initialize(new AbstractYouTubeListener() {
  @Override
  public void onReady() {
    youTubePlayerView.loadVideo("6JYIGclVQdw", 0);
  }
}, true);

The AbstractYouTubeListener is just a convenience abstract class, the initialize method requires a YouTubePlayer.YouTubeListener.

The second parameter is a boolean, set it to true if you want the YouTubePlayerView to handle network events, if you set it to false you should handle network events with your broadcast receiver. Reed the doc for more info.

Is possible to listen to specific events such as full-screen on/off, playback events etc.

Use the methods youTubePlayerView.setCustomActionRight and youTubePlayerView.setCustomActionLeft to add/remove custom actions at the left and right of the play/pause button.

youTubePlayerView.setCustomActionRight(ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_pause_36dp), new View.OnClickListener() {
  @Override
  public void onClick(View view) {
  }
});

if the OnClickListener is null the custom action will be invisible.

androidyoutubeplayer's People

Contributors

pierfrancescosoffritti avatar kwatra avatar askarsyzdykov avatar denino avatar

Watchers

 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.