Android-YouTube-Player


Source link: https://github.com/PierfrancescoSoffritti/Android-YouTube-Player

Android-YouTube-Player

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.

Why does this library exists?

This library has been developed out of necessity. The official library provided by Google for the integration of YouTube videos into Android apps is the YouTube Android Player API. Its many bugs and the total lack of support from Google made it impossible to use in production. I've tried to use it but my app was crashing because of internal bugs in Google's player, ( sone bugs have 3+ years old bug reports) and, at the moment, no update has been released for almost a year. This library provides a stable and open source alternative to the official YouTube Player.

Apps using this library: (send me an email if you want to add your app to the 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 {

compile 'com.github.PierfrancescoSoffritti:AndroidYouTubePlayer:2.0.0' 
}
 

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

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

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);
 

The second parameter of the initialize method 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 own broadcast receiver.

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

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

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();
 

Use the methods uiController.setCustomAction1 and uiController.setCustomAction2 to add/remove custom actions at the left and right of the play/pause button.

uiController.setCustomAction1(ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_pause_36dp), new View.OnClickListener() {

  @Override
  public void onClick(View view) {

  
}
 
}
);
 

Resources

A collection of examples demonstrating different techniques for automated testing with Espresso.

Android Library to handle soft keyboard visibility change event. Show/hide keyboard methods are also included.

An implementation of a circular button made of paper that lifts and emits ink reactions on press.

FontIcon is a simple library which allows to use font-based icons in Android.

Xdroid - extensions library for any Android app.

An Android image processor library providing a variety of transformations for Fresco.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes