Utility library around using YouTube inside your android app.
YouTube component for Android, iOS and React. This is a suite of utility libraries around using YouTube inside your Android, iOS or React Native app.
Playing Youtube on Android (specially inline) comes with some challenges :
inline-youtube-view for Android checks if the services are available and will fall back gracefully to using WebView in the event they are not.
YouTubePlayerView : The YouTubePlayerView provided by the YouTube SDK comes with a restriction that the activty hosting this needs to extend from YouTubeBaseActivity. This view removes these restrictions.
Add it in your root build.gradle at the end of repositories :
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Add the dependency
dependencies {
implementation 'com.github.flipkart-incubator:android-inline-youtube-view:1.0.3'
}
Start an YouTubeActivity intent with apiKey and videoId. This will play the youtube video in a new activity in fullscreen mode.
Intent intent = new Intent(MainActivity.this, YouTubeActivity.class);
intent.putExtra("apiKey", Constants.API_KEY);
intent.putExtra("videoId", "3AtDnEC4zak");
startActivity(intent);
Also, make sure that you add the activity in the AndroidManifest.xml file.
<activity android:name="com.flipkart.youtubeview.activity.YouTubeActivity" />
Create an instance of YouTubePlayerView inside a fragment. To initialize the player, you need to call the initPlayer method with following params:
YouTubePlayerView playerView = new YouTubePlayerView(context);
playerView.initPlayer(Constants.API_KEY, videoId, "https://cdn.rawgit.com/flipkart-incubator/inline-youtube-view/60bae1a1/youtube-android/youtube_iframe_player.html", playerType, listener, fragment, imageLoader);
We have open-sourced the inline-youtube-player for iOS also.
The easiest way to contribute is by forking the repo, making your changes and creating a pull request.