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?
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.
Youtube Player don't allow any view overlay it. Just using setVisibility(View.GONE) for all view overlay it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With