Youtube API Player on Android Automatically pauses every 2 seconds - android

I'm making an app that uses the YouTube API to play YouTube videos. When I go into full screen mode, I switch the player style to CHROMELESS because I want to create my own set of media controls.
I have developed a set of gestures that map to changing volume, brightness, and seeking. When these changes occur, a progress bar pops up over the video showing the user their changes in real time. I have placed all my Views in a single FrameLayout in order to get the progress bars to show up on screen when the player is fullscreen.
The problem is that (before I added volume control functionality) the video would automatically pause as soon as I entered fullscreen mode. I am handling orientation and screenSize changes myself. I noticed that it would pause roughly 2 seconds after my personally made seekbar would pop up.
So for testing, I altered my code by NOT changing the player style to CHROMELESS, that is, I left it as DEFAULT. I removed my seekbar as well and now the video worked fine; I could change brightness and play the video with no problem. During another test, I removed all instances of youtubePlayer.pause() from my code, left the seekbar in, and changed back to CHROMELESS. But the problem returned--so it must be something to do with the seekbar.
Now, however, I have added volume control functionality and when I run it (even when I'm not fullscreen) the player pauses almost immediately after I press play and it doesn't work at all afterwards.
Can anyone help me out? I'll add some of my code when I get back to my computer. I really appreciate your help.

Following reasons are among the most common ones:
UNAUTHORIZED_OVERLAY - Other views overlapping with youtube view
PLAYER_VIEW_TOO_SMALL - Youtube view too small
USER_DECLINED_RESTRICTED_CONTENT - Trying to play restricted content
BLOCKED_FOR_APP - Certain videos are blocked for app.
You can read about these and other problems in detail at link

You can not Cover anyView on YoutubePlayView that should be clean.
try the following
<com.google.android.youtube.player.YouTubePlayerView
android:id="#+id/player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

If you want that youtube android player controls do not show after every two seconds. you have to true focusable in your layout.
<com.google.android.youtube.player.YouTubePlayerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/youtube_view"
android:focusable="true"
android:layout_height="match_parent"
android:layout_width="match_parent" />

I think your problem is due to your controls overlaying the player. Take a look at your logcat to verify.
As mentioned in the YouTubePlayerView JavaDoc, "it is not permitted to overlay the [player] view with other views while a video is playing".
Take a look at this question: Views overlayed above YouTubePlayerFragment or YouTubePlayerView in the layout hierarchy cause playback to pause immediately
This problem can be easily solved using a library that I've build: Android-YouTube-Player. Other than being more stable than the official API this library gives you more freedom, eg. you can overlay whatever you want to your player.

Please check the logcat to identify your issue.
When i had the issue, it was because of UNAUTHORIZED_OVERLAY.
<RelativeLayout
android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/scImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<FrameLayout
andriod:id"#+id/youtube_parent
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
The imageview was below the framelayout which had the youtube player. I moved it to the top (The final, fixed layout is the example above) and it started to work.(I tried setting the Zindex it didnt help).

For my case, I have the status bar in the player activity. Just set the acitivity with full screen style to fix the issue

Remove paddings and margins in your Youtube Viewlayout
The problem is only with the layout, the YouTube Player doesn't permit any view staying over it, neither invisible nor transparent.
In order to make this visible in your device, enable layout bounds in developer option. (warning with paddings and margins)
OR
Use below code. I hope it's working
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Related

Chromecast v3: Mini Controller showing progressbar instead of Play/Pause button

I am using below way to integrate mini_controller in my chromecast app. However, I always seeing progressbar instead of pause/play button in mini controller.
<fragment
android:id="#+id/cast_mini_controller"
class="com.google.android.gms.cast.framework.media.widget.MiniControllerFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:castControlButtons="#array/cast_mini_controller_control_buttons"
app:castProgressBarColor="#color/colorPrimary"
app:castShowImageThumbnail="true" />
Can anybody please suggest what can be the issue it might be?
I tried various articles and none of them able to resolve this issue. All is working fine except the fact that I can not pause the chromecast video through mini controller inside my app as its showing progressbar always.
Note: My application is using queuing mechanism in order to load the chunk of videos at once.
Make sure you are specifying the correct set of buttons for the fragment:
<array name="cast_mini_controller_control_buttons">
<item>#id/cast_button_type_rewind_30_seconds</item>
<item>#id/cast_button_type_play_pause_toggle</item>
<item>#id/cast_button_type_forward_30_seconds</item>
</array>
I know it's old, but... I've had a similar problem, - always is showing only 2 instead of 3 buttons. My solution is 'app:castShowImageThumbnail="false"'. After that, 3rd button appears.
https://developers.google.com/cast/docs/android_sender/customize_ui#choose_buttons
"Note: If app:castShowImageThumbnail="false", the album art will be hidden and slots 1, 2, and 3 will be available for control buttons. Otherwise, since the album art will be shown in slot 1, you can provide an empty button for slot 1 and control buttons for slots 2 and 3."

Exoplayer custom overlays

I am using ExoPlayer as a player for my app. I've seen they offer a bunch of ready-to-use player controls that are somewhat customizable, which is in my interest.
However my app has a bunch of other custom controls (i.e. a scoreboard) that I would like to update myself. So if I use exoplayers customization:
<com.google.android.exoplayer2.ui.SimpleExoPlayerView android:id="#+id/player"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent"
app:controller_layout_id="#layout/custom_controls"/>
And i put my scoreboard in this layout, I cannot get ahold of these controls programmatically to update them (or at least I haven't seen any getPlaybackControls or getController methods).
I would like to take advantage of the builtin timer, play/pause controls, timebar, etc.
After trying to understand what pskink has said, it really is the case that if you use app:controller_layout_id and specify a PlaybackControlView for SimpleExoPlayerView, you can get any of the elements such as the play, pause, repeat toggle ImageButtons by using findViewById from the SimpleExoPlayerView instance itself rather than trying to inflate the xml representing PlaybackControlView.

Youtube API - Touch Event Passed to Views Behind Youtube Player

I am using a YoutubeAndroidPlayerAPI in my Android App.
In my YouTubePlayerSupportFragment I am setting youtubePlayer.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT); so that I can change between Fullscreen without having to rebuffer each time I do so.
For that I removed the navigation bar please see my previous SO question about it. So now the player is playing fine. But somehow the touch events are passing down behind the player (i.e. to views behind youtube player) but Only when touch events are below the player's SeekBar (In FullScreen Mode).
Is there any workarounds to this problem?
Any one knows of any open issues regarding this issue?
Try adding android:clickable="true" to the top ViewGroup of your fragment's layout file.

Android VideoView on a Translucent Activity

I have an app that I'm working where in one activity I'm using a VideoView while setting the theme for that activity translucent (transparent) : android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"
However I'm noticing odd behavior from the videoView - for a split second before the video starts playing (it's auto play) the frame where the videoView is itself transparent and you can see the activity behind it. For reference the activity in question has other elements to it and the video is framed.
Is there anyway to make this black or even a custom image that covers the frame before the video starts?
videoView.setBackgroundColor is buggy and actually changes the foreground color and keeps the frame that color while playing...
thanks for your time!
videoView.setZOrderOnTop(true);
SurfaceView (and VideoView as subclass) is placed behind the window by default. So you should call: videoView.setZOrderOnTop(true) if you want to place it on top (to make it non transparent).
You can cover the ViewView with another View and then as soon as video playing starts you can animate this View out, let's say quickly changing its alpha to 0.0.
Please read this response in other SO thread, i think it's the solution for this problem, at least it worked for me

Video playing in webview always hiding other views?

I have a webview that's playing a video, and I want it to appear behind some other views, but I can't seem to make it happen. I've tried simply just sending the foreground views to the front with bringChildToFront(View v), but no cigar. Any thoughts?
Edit: Some more details: The webview plays a video using flash, and the webview is the size of the entire screen. I have some stuff I want to pop up in front of the video, but they only stay behind the video. They're definitely there, as they receive touch events and stuff, but just hidden away from view by the video.
Since the Flash player will essentially pre-empt any other views in the window, you'll just have to do one better over Flash: use another window on top of the main window.
Android allows you to do this by using the PopupWindow class.

Categories

Resources