-
-
Notifications
You must be signed in to change notification settings - Fork 763
Home
Pierfrancesco Soffritti edited this page Oct 16, 2017
·
12 revisions
To get started using AndroidYouTubePlayer simply add the dependency to your module-level gradle file.
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:1.0.0'
}
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.*
A sample project that shows how to use the library is available in the sample module. You can also download the sample apk here.
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 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() {
initializedYouTubePlayer.loadVideo(videoId, 0);
}
});
}
}, true);
In this example I am loading a new video as soon as the player is ready.