4

The question has been asked before here, yet I would like to provide a little more information. The YouTubePlayerView often gives a black outline when scrolling, this can happen after pausing and changing rotation. This appears to happen when I scroll and it gets overlaid, so it pauses (to prevent that controls get hidden). The pausing isn't a problem since the user isn't watching the video but the black screen is. This happens on a Galaxy Tab 2 running Android 4.0.3, also on a Xperia T on 4.1.2, on a One X running 4.2.2 and Desire running 2.2.2 does the problem not occur.

Some more info: The video-image that is paused appears to be stretching (On Xperia T) with the top of the screen while scrolling down. The black field starts scrolling over other content when it looks like it reached its minimum size.

Warning text: YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is not contained inside its ancestor android.widget.ScrollView@41290ca0. The distances between the ancestor's edges and that of the YouTubePlayerView is: left: 20, top: 0, right: 20, bottom: -11 (these should all be positive).

This is my code:

    <TextView
        android:id="@+id/textView"
        android:gravity="center"
        android:textSize="25sp"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="@string/header" />

   <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0dp" >

        <LinearLayout
            android:gravity="center_horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" > <!-- In a linear layout so it is possible to set it in the middle -->

            <com.google.android.youtube.player.YouTubePlayerView
                 android:id="@+id/youtubeplayer"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:visibility="gone" >
             </com.google.android.youtube.player.YouTubePlayerView>
        </LinearLayout>
   </ScrollView>

So my question is, is there a way to get rid or prevent the black patch from showing?

Currently I have a large workaround, when the user starts scrolling, the youtubeplayer will be released and a image with a play button will take its place, when the user presses the button the youtubeplayer will reinitialize and continue the video.

Community
  • 1
  • 1
Roy
  • 656
  • 12
  • 28
  • [See my reply in this post maybe can help you ][1] [1]: http://stackoverflow.com/questions/16067783/android-youtubeplayer-with-unauthorized-overlay-on-top-of-player – lucasddaniel Dec 08 '13 at 20:40
  • Thanks for your time, I know there are no views allowed over it but the client wants it. Yet I would hope the youtube would handle this correctly on all platforms by pausing or releasing instead of giving a black outline. – Roy Dec 10 '13 at 10:38

1 Answers1

0

Actually there is a workaround for this problem. You need to put a listener to your ScrollView and catch the Y distance. When the Y distance is close to the height of the YoutubePlayerView you need to pause the video.

scrollView.getViewTreeObserver()
                .addOnScrollChangedListener(() -> {
                    onScroll(scrollView.getScrollY()); 
                    }
                });


private void onScroll(int position)
    { 
            if (position>300 && position <400)
            {
                canPauseOnScroll=false; 
            } 

            if (canPauseOnScroll)
            {
                canPauseOnScroll=false;
                ytHelper.getPlayer().pause();
            } 
    }
stavros.3p
  • 2,244
  • 6
  • 20
  • 37