Views overlayed above YouTubePlayerFragment or YouTubePlayerView in the layout hierarchy cause playback to pause immediately
Asked Answered
M

5

18

I'm using the YouTube Android Player API and want to overlay a view on top of a YouTubePlayerFragment in order to display contextual information and controls above the playing video.

Unfortunately it seems playback does not work correctly in either a YouTubePlayerFragment or YouTubePlayerView whenever a there is one or more views stacked above the player in the layout hierarchy. Playback occurs for less than half a second before immediately pausing.

The issue can be reproduced by using the following layout for the Simple PlayerFragment demo that ships with the SDK:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

  <fragment
      android:name="com.google.android.youtube.player.YouTubePlayerFragment"
      android:id="@+id/youtube_fragment"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/>

  <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textAppearance="@android:style/TextAppearance.Small"
      android:layout_alignParentTop="true"
      android:text="@string/playerfragment_text"/>

</RelativeLayout>

I have tried various layout configurations using both FrameLayout and RelativeLayout but the issue is always the same. I realise this API has been released as "experimental", but if this is a known issue it is a pretty major blocker for a lot of implementations. Does anyone have a good solution or workaround?

Monotonous answered 23/12, 2012 at 19:35 Comment(0)
S
16

Jeff - this works as designed. Overlays on top of any of our YouTube players (including the YouTube Android Player) are not supported. When an overlay is detected, playback stops and the log contains information helpful in debugging the issue. We do support Action Bar overlays, take a look at this demo to learn more: https://developers.google.com/youtube/android/player/sample-applications#Overlay_ActionBar_Demo.

Statutory answered 24/12, 2012 at 1:7 Comment(10)
Thanks Jarek. This seems like something that should be mentioned more prominently in the documentation and perhaps be handled more explicitly at runtime. I can successfully display a dialog fragment over the player and set its background drawable transparent to achieve the desired effect (with a bit more effort) so I'm not sure what this design restriction is attempting to achieve.Monotonous
Jeff - overlays are currently against our ToS hence the restriction. I agree we should make it more prominent and we're working on making updates to better cover it.Statutory
@wjarek ToS speaking, is it ok to overlay views once the YouTube player is paused?Wineglass
I think it would reset the position of the player if you tried that. The code doesn't even let you do it.Hyacinthhyacintha
Telling this up front in developer docs is a good idea; I spent lots of time debugging my overlay attempts before I found the limitations mentioned in forums.Kondon
@GunnarForsgren-Mobimation can you please put a link where it is said that it is the limitation from the API? I also having this issue and need to have any conclusion on that.Hanforrd
ok I got the link. Please check error which is clear listed in the Document with in below link: Please check public static final YouTubePlayer.ErrorReason UNAUTHORIZED_OVERLAY with in below link. developers.google.com/youtube/android/player/reference/com/…Hanforrd
Can you please explain the reason behind this decision? Right now I am implementing youtube iframe api in webview, just to be able to overlay it.Aristarchus
When I add a fragment after adding a you tube fragment in container, it also shows unauthorized overlay. But I want to add fragment because in my app, use should be able to see previous watched video. Any solution to this?Maihem
@JarekWilkiewicz Thanks! I am getting same error in ViewPager Adapter. I am using framelayout with YouTubePlayerFragment. Here is the detail question https://mcmap.net/q/672380/-viewpageradapter-youtube-video-playback-stopped-due-to-unauthorized-overlay-on-top-of-player/1468354 Hoping you will help/respond.Fleet
R
4

Youtube Player don't allow any view overlay it. Just using setVisibility(View.GONE) for all view overlay it.

Reichenberg answered 11/2, 2014 at 3:21 Comment(1)
yes that works fine. but it is not good way to make YouTubePlayer working properly.Hanforrd
S
3

It is not possible to add buttons as overlays above the player as specified by Google, otherwise the player will stop:

https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayerView

Note that while videos are playing, this View has a minimum size of 200x110 dp. If you make the view any smaller, videos will automatically stop playing. Also, it is not permitted to overlay the view with other views while a video is playing.

This view does not support padding. To achieve the same effect, wrap the view in another ViewGroup or give it margins.

Padding is also not supported on YouTubePlayer.

To overlay your view on video, I will recommend you to use ExoPlayer, It is not part of the android sdk, but it's recommended by google and included in android developer documentation :

http://google.github.io/ExoPlayer/

It's also good to mention that Exoplayer is used in youtube application.

Selenography answered 12/9, 2015 at 15:13 Comment(1)
Hi,Is it possible to put text in player view using ExoPlayer?Handel
I
0

You can set the player theme to YouTubePlayer.PlayerStyle.CHROMELESS and then implement your own controls below.

I am having an issue where I can not find a good resource on how to re-implement the seek bar with a custom layout.

Ideational answered 23/2, 2014 at 23:2 Comment(0)
D
0

Volla !! I have got one scenario where this issue was coming in devices lollipop and above and it was because of the status bar . I hide the status bar problem solved. Just wrote it as an answer in case if its helps others :)

Dumbstruck answered 2/6, 2017 at 9:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.