Exoplayer custom overlays - android

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.

Related

Custom layout for Google Cast 'ExpandedControlsActivity'

Is it possible to have a custom layout for 'ExpandedControlsActivity' in an android application? I want to add a button to the standard layout which will allow the user to choose from different video streams (low/high).
At the moment i am using the standard one;
Google codelabs - Cast SDK v3 Android Codelab
No, you do not have control over the layout. You can only use one of the pre-defined actions for the buttons on that screen. You can, however, write your own custom activity and have that act as the Expanded Controller (i.e. be invoked if user, say, taps on the mini controller). Given that it is easy to use UiMediaController to bind ui components of your app to the remote session, writing such activity shouldn't be too much trouble.
For addition of any custom layout you need to modify activity_layout.xml and activity.java in order to add the feature.
But you dont have Access to the ExpandedControlsActivity layout file as it is extended from ExpandedControllerActivity.
So only way is to write your own activity and than use that instead of ExpandedControlsActivity.

Youtube API Player on Android Automatically pauses every 2 seconds

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);

How to get overlay on Video Player in activity

On Video players such as Youtube, I often see that when the user taps on the video view a sort of overlay shows up where the user can choose actions like: “share”, “add to playlist”, “pause”, etc. Basically it’s whatever the developer wants. The developer seems to be able to choose what the icons are, where they go, etc.
I would like to know how it’s done. For example, are they using a VideoView with an overlay? Are they using a FrameLayout with a VideoView and a RelativeLayout on top of the VideoView? I just need some advice in the right direction as I don’t know where to start. Thanks. For simplicity, I am looking to add a Youtube style video player to my activity. And by Youtube style, I am referring to the aforementioned interactions.
I would like to know how it’s done
I am sure that the implementation varies widely.
For example, are they using a VideoView with an overlay?
AFAIK, few professional-grade apps use VideoView, simply because VideoView offers little in the way of events or control. More likely, they are using something else backed by MediaPlayer or third-party media libraries (e.g., ExoPlayer).
Are they using a FrameLayout with a VideoView and a RelativeLayout on top of the VideoView?
No, because that would be two VideoView widgets. However, whatever their video surface is probably resides in a RelativeLayout or FrameLayout, with the overlay as another child of that same container, though I am sure that there are other approaches.
You are welcome to use uiautomatorviewer to try to learn more about the view hierarchy of particular apps of interest.

Create custom media player like Youtube in Android

I have to create media player like youtube player.Actually if i use VideoView for play video and MediaController for controll video(MediaController onlyu provides play,pause,next,pre and seek options).But in my player i have to add one more option i.e bandwidth(I would have three bandwidth and on clicking on bandwidth video will play).So please suggest me.
As far I know, MediaController doesn't give many opportunities to be customized. So, you have two options depending on your UI requirements and the effort you are willing to do.
The hard way: You can just get rid of Android MediaController and
implement your own media controller, since you are not bound to use
it. MediaPlayer (through VideoView) provides you the needed
functions to build it: pause(), play(), resume() methods and event
listeners like onPrepared, onStopped, etc. To display the progress
bar you can use SeekBar, but you will have to code the interaction
with MediaPlayer (this is, the progress bar will not move alone).
The easy way: you can find another place to put your bandwith
button, for instance, on the top of the screen. You might even place
your button over MediaController.
You just have to create a layout properly combining the GUI elements you need. VideoView can be used with other GUI elements like buttons and can be nested within layouts like RelativeLayout and LinearLayout.
So, if you want your bandwidth button adjacent to VideoView, you may use LinearLayout, if you want your bandwith button over the video surface, like MediaController, you may use RelativeLayout, managing properly the layers.
have a look at SurfaceView, that will give you an idea on not bounding your logic with player.

Android homescreen widget animations

I'm looking into creating a widget that supports animation, ideally via the android.view.animation framework, otherwise by setting properties on the remote views in code triggered from a background service.
Does anyone have any experience with either of these approaches, and is what I'm trying doable, or am I heading up a blind alley?
It's actually possible to animate RemoteView widgets. The problem is it is super restrictive which is by design because of the security implications of running custom code in a system process.
What I mean by this is that Android will only work with animations that are expressed in res/anim xml files that are tied to layouts via xml. Some RemoteView widgets support this
An example of this is the News and Weather app widget that comes on a stock android system. What it is doing is using a ViewFlipper to cycle through each news story every 10 seconds or so.
<ViewFlipper android:layout_width="match_parent" android:layout_height="wrap_content" android:measureAllChildren="true" android:flipInterval="10000" android:autoStart="true"
android:inAnimation="#android:anim/fade_in" android:outAnimation="#android:anim/fade_out" android:animateFirstView="true">
<TextView android:id="#+id/Description1TextView" style="#style/AWCText.Centered" android:layout_width="match_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/Description2TextView" style="#style/AWCText.Centered" android:layout_width="match_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/Description3TextView" style="#style/AWCText.Centered" android:layout_width="match_parent" android:layout_height="wrap_content"/>
<TextView android:id="#+id/Description4TextView" style="#style/AWCText.Centered" android:layout_width="match_parent" android:layout_height="wrap_content"/>
</ViewFlipper>
In this example you can tie pending intents to each TextView. So when a user clicks on any one a different action can occur.
Lastly, Android has been slowly adding support for animated views in each version. For example TransitionDrawables (cross fading selector drawable) don't cross-fade until Android 3.0.
It's possible, but use it with caution, since it is very heavy to the default homescreen implementation and you shouldn't use it very often.
In the Mario Coin Block widget, I am using such technique to do the animation, you can checkout the source code: http://code.google.com/p/mario-coin-block/source/browse/trunk/MarioWidget.CoinBlock/src/com/gueei/mario/coinBlock/view/CoinBlockView.java
Basically the idea is manually draw on an offscreen Bitmap, and replace the BitmapView's bitmap with it using RemoveViews Call.
I agree with the other answers here, so I won't re-iterate - limited animation on a widget is possible, but heavy on resources, it might make the home screen slow and less responsive, and battery drainer. From my experience - it doesn't run smooth.
So the bottom line is - it's ok if it's only few frames changing from time to time, or for some effects seldom upon an event (for example user press or some event from your service.
But here's an idea that probably does not directly answer your question, but may be a suitable alternative (I don't know your use case, it might be not relevant at all)
Did you consider implementing a live wallpaper?
pros -
highest quality animation,
can be controlled from the background
cons -
not interactive,
replaces the user's wallpaper... and it's hard to satisfy everyone's taste
You can have only simple animations like fadeIn or fadeOut on your widget, it's very simple, you don't need any layout animations, just use ViewFlipper(it took me 3 days of investigation to find out that it is so easy).
Yet it's imposiible to write something really great without using custom launchers
Animations are impossible on RemoteViews, and RemoteViews updates can occur at a rate of once every 30 minutes (or manually)...
Anyway, you can try the following link: is-there-a-way-to-animate-on-a-home-widget

Categories

Resources