Good afternoon. There is the next problem with the integration of youtube api. When you click on the playlist in the video, after two seconds it pauses. The player itself is in the fragment, which is in the ViewPager. The search for the buzz prompted that you need to run the video when the fragment becomes visible to the user. In the ViewPager I have fragments of three different types. I added the listener turning over the fragments, and in it, if this is a fragment from the video, I launch the video.
mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { if(adapter.getItem(position) instanceof VideoFragment){ VideoFragment videoFragment = (VideoFragment) adapter.getItem(position); videoFragment.playVideo(); } } @Override public void onPageScrollStateChanged(int state) { } }); This method worked. but it is in page mode. And if I open the viewpager immediately on the video fragment, the problem does not disappear. To solve this problem, I tried to implement a player initialization listener, from a fragment, and when the player is initialized. run through the video fragment method. did not work.
VideoFragment videoFragment = new VideoFragment(new VideoFragment.VideoFragmentListener() { @Override public void videoFragmentCreate() { Log.d(LOG_TAG, "videoFragmentCreate "); if(adapter.getItem(positionArticle) instanceof VideoFragment){ VideoFragment videoFragment = (VideoFragment) adapter.getItem(positionArticle); videoFragment.playVideo(); } } }); adapter.addFragmentForward(videoFragment); <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/pagerArticles"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ProgressBar style="@style/Widget.AppCompat.ProgressBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/progressVideo" android:layout_alignParentTop="true" android:layout_alignParentStart="false" android:layout_centerInParent="true" /> <TextView android:text="annotation_video" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/annotation_video" android:textSize="24sp" android:fontFamily="serif" android:textStyle="normal|bold" android:layout_marginLeft="13dp" android:layout_marginRight="13dp" android:layout_marginTop="5dp" /> <RelativeLayout android:layout_width="match_parent" android:layout_below="@+id/annotation_video" android:id="@+id/layout" android:layout_height="235dp"> <fragment android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment" android:id="@+id/youtubesupportfragment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="5dp" /> </RelativeLayout> <TextView android:text="text_video" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/text_video" android:layout_below="@+id/layout" android:textSize="17sp" android:layout_marginTop="5dp" android:layout_marginRight="13dp" android:layout_marginLeft="13dp" /> </LinearLayout> </android.support.v4.widget.NestedScrollView> </RelativeLayout>