ExoPlayer2 Scaling - android

I have an Activity that contains a FrameLayout where ExoPlayer takes place.
This activity support both orientations and video aspect ratio should be preserved.
According to ExoPlayer docs, for the setResizeMode we can have one of the following:
RESIZE_MODE_FIT,
RESIZE_MODE_FIXED_WIDTH,
RESIZE_MODE_FIXED_HEIGHT,
RESIZE_MODE_FILL,
RESIZE_MODE_ZOOM
In my case, since I don't know the video size nor the device orientation, I can have two scenarios:
Video is larger than my Viewport, so I would like to have RESIZE_MODE_FIT to scale it down
Video is smaller than my Viewport, so I would like to have RESIZE_MODE_ZOOM to scale it up.
But in the end I could not find a way to achieve this behavior.
If I set RESIZE_MODE_FIT, small videos does not fill my Viewport.
If I set RESIZE_MODE_ZOOM, large videos overflow the Viewport.
Thanks.

Related

How to overlap a SurfaceView beyond the display area in Kotlin?

I have this school project where I have to adjust a video content
depending on the aspect ratio of the display area based on the set Screen Format.
I'm already done with the following Screen Formats:
Stretch-to-Fit
Letterbox/Pillarbox
But I just can't seem to nail the Crop format.
BACKGROUND:
Cropping happens when the display area aspect ratio is smaller than that of the video content
For example:
The display area is in (4:3) aspect ratio and video content is at (16:9) aspect ratio,
What is expected is:
Crop Format
The height of the video content will match that of the display area but doing so will also
increase the width of the video content. But the Crop format will just crop both sides of the
video content to match the display area.
NOTE:
I don't have access to the MediaPlayer class since I just pass the SurfaceView to another
component so the video content will be drawn.
It's been a few weeks now and I'm at my wits end that's why I decided to post here
for help.
Thank you
WHAT I ALREADY TRIED:
I already tried Scaling the SurfaceView using the setScaleX(2.0f) method.
But it doesn't seem to go beyond the display area.
I also tried setting the LayoutParams width to twice the value.
But it doesn't go beyond the display area too.

ExoPlayer2 - resizing video after playerView.setRotation(90)

I am testing ExoPlayer2 using the google exoplayer-codelab-00 app https://github.com/googlecodelabs/exoplayer-intro . The goal is streaming from an IP camera. I have to rotate the camera video stream from landscape to portrait, shown on device in portrait mode.
I changed surface type to TextureView, in PlayerActivity.initializePlayer set playerView.setRotation(90). The video appears correctly rotated, but it is scaled at the initial size which would have been shown without the rotation, like this.
I tried changing width and height in playerView.getLayoutParams() + playerView.setLayoutParams(), but the video is never shown higher. Change of RESIZE_MODE_FIT to RESIZE_MODE_FILL just expands the video to fit the new width, but the height is not changed, like this.
Setting player.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT) makes no difference either.
IMO some layer of the view stack does not get rotated with the playerView.setRotation(90) and the unrotated dimensions somehow constrain the rotated video. I want the rotation fixed, it is called before setting media item. The device will always be positioned in portrait mode (fixed installation). Thanks a lot for any hints, I am completely new to Android.

Android SurfaceView resize to fit screen 16:9

Hello! Is there a good way of having a 16:9 SurfaceView, and then resize it bigger until it touches a screen edge? (so the SurfaceView is at its biggest size and still 16:9 and not outside the screen)
I have heard it is called letterbox, but havn't found any tutorial about it.
Thanks
There are two relevant sizes, the size of the Surface and the size of the View.
The size of the Surface is determined by the size of the video being rendered to it. You can't change this. A 720p video will set the size to 1280x720.
The size of the View is determined by the layout code. This can be set from within your app.
The system compositor (SurfaceFlinger) will scale the contents of the Surface so they fit in the View. To avoid distortion, you want to maintain the same aspect ratio. You do this with a custom FrameLayout.
For an example, see how AspectFrameLayout is used in Grafika's video players, e.g. this chunk of code.

Android WebView scaling video to fit into linearlayout?

I have a webview and it displays a video link over the internet. Bu when the video was loaded it scales the view bigger than my linearlayout. But I want it fit into my linear layout. I've tried some methods like LayoutAlgorithm.SINGLE_COLUMN or writng the scale property manually but I couldn't find the right solution.
How can I scale it dynamically?
You may like to try setInitialScale ( http://developer.android.com/reference/android/webkit/WebView.html#setInitialScale(int) ). This will help to "zoom" the page (or the video) shown in the Webview to fit a particular width. Actually the size of HTML5 video in that page is decided by webkit engine and we cannot directly change its size from App layer.
You may also want to calculate the expected width yourself, due to the fact that Android devices have hundreds of screen resolutions and the width of your LinearLayout may vary on defferent devices.

How to scale video on a SurfaceView larger than the window on Android?

Android 2.2 (on a media player boxtop) with a display of 1280x720.
My video is 480px high, 720px wide; standard definition.
I know that if change the layouts of a SurfaceView, the video is scaled to fit whichever is smallest to maintain aspect ratio.
This is great, except I can only scale up to the height of the screen. This is a problem as there is are black bars being broadcast on the top/bottom of the video.
See here:
http://i.imgur.com/dsiLw.jpg
I would need to make my SurfaceView (and the window) larger than the screen.
I know about FLAG_LAYOUT_NO_LIMITS, on WindowManager:
http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_LAYOUT_NO_LIMITS
It is supposed to allow my window to expand out past the screen... but I can't seem to get this working. It always seems to resize it to 1280x720px no matter what I do.
If you could help me get this so I can expand my surfaceview video so it looks full screen (clipping the tops video), I will be extremely grateful.
:)

Categories

Resources