Youtube-Android-Player-Helper


Source link: https://github.com/JackDinealKIM/youtube-android-player-helper

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

Or Maven:

<dependency>
<groupId>com.jaedongchicken</groupId>
<artifactId>ytplayer</artifactId>
<version>1.4.2</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.2 - fix handler issue. v 1.4.1 - Solved UMG block issues. 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. 

Resources

Yet another android custom progress view for your music player.

A minimalist, View-based application framework for Android.

Plaid is a showcase of material design that we hope you will keep installed. It pulls in news & inspiration from Designer News, Dribbble & Product Hunt. It demonstrates the use of material principles to create tactile, bold, understandable UIs.

Android Library for JoyStick View (customizable, small and lightweight).

Passwy is a simple open sourced Password-Generator app for Android.

Convert any Java object to JSON for easier debugging.

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