How To make a YouTube Video Player app in Android Studio -Sample
Step 1 - Go to GitHub library github Link and copy dependencies and paste in your build.gradle file.
implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:10.0.5'
Step 2- write given bellow code in your .xml file
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="25">
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
android:id="@+id/youtube_player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:showSeekBar="true"
app:autoPlay="false"
app:showVideoDuration="true"
app:showVideoCurrentTime="true"
app:showYouTubeButton="false"
app:showFullScreenButton="false" />
</LinearLayout>
Step 3 - write given bellow code in your .java file
YouTubePlayerView youTubePlayerView = findViewById(R.id.youtube_player_view);
getLifecycle().addObserver(youTubePlayerView);
String youtubeId = "jNQXAC9IVRw";
youTubePlayerView.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
@Override
public void onReady(@NonNull YouTubePlayer youTubePlayer) {
String videoId = youtubeId;
youTubePlayer.loadVideo(videoId, 0);
}
});
_-_ Screenshot _-_
Tags:
Android Development