Open huanglongyu opened 4 months ago
Hi, can you share a video of the issue?
@PierfrancescoSoffritti
https://github.com/user-attachments/assets/86b41a29-5f1b-41ab-b2cb-7dc65070ce4a
I'm sorry for the late reply. The attachment is a recorded video
public class ViewPager2Fragment extends Fragment {
private final String videoId = VideoIdsProvider.getNextVideoId();
@SuppressLint("SetTextI18n")
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
LinearLayout linearLayout = (LinearLayout) inflater.inflate(R.layout.fragment_view_pager_2, container, false);
Button button = linearLayout.findViewById(R.id.add);
button.setText("add " + videoId);
button.setOnClickListener(v -> {
YouTubePlayerView youTubePlayerView = new YouTubePlayerView(button.getContext().getApplicationContext());
youTubePlayerView.enableBackgroundPlayback(true);
youTubePlayerView.setEnableAutomaticInitialization(false);
youTubePlayerView.initialize(new AbstractYouTubePlayerListener() {
@Override
public void onReady(@NonNull YouTubePlayer youTubePlayer) {
super.onReady(youTubePlayer);
youTubePlayer.loadVideo(videoId, 0);
}
}, false, IFramePlayerOptions.Companion.getDefault());
linearLayout.addView(youTubePlayerView);
});
return linearLayout;
}
}
Problem
Summary
There is a horizontally scrolling ViewPager2, where each item is a Fragment. The first Fragment has loaded a YouTubePlayer and has already started playing. After sliding to the subsequent Fragments, the playback stops.
What I've tried
the first Fragment demo code