I'm a beginner in android development with java
and I have some code that inserts and plays a youtube
video in a fragment .
private YouTubePlayerView youTubePlayerView;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
binding = FragmentSlideshowBinding.inflate(inflater, container, false);
View root = binding.getRoot();
youTubePlayerView = root.findViewById(R.id.video1);
getLifecycle().addObserver(youTubePlayerView);
youTubePlayerView.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
@Override
public void onReady(@NotNull YouTubePlayer youTubePlayer) {
super.onReady(youTubePlayer);
String videoID = "yyduqrCpKGg";
youTubePlayer.cueVideo(videoID,0);
}
});
return root;
}
With my code above I can create and play a video for a single url. How can I perform the code above for multiple IDS with urls and create multiple videos instead of manually doing it?
My YoutubeVideo.xml
for one single video
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
android:id="@+id/video1"
android:layout_width="match_parent"
android:layout_height="216dp"
app:autoPlay="false"
app:showFullScreenButton="true" />
The pierfrancescosoffritti youtube view acts just like a normal view .So you can create a recycler view and then pass a list of URL to the recycler view.