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.
Related
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.
My issue is when a video that was recorded in portrait mode is rotated to landscape, the video gets cut off and I have to scroll to see the rest of the frame. Currently the video is in a webview, view with styling that sets width and height to 100%. This is specific to android as ios seems to handle rotating appropriately.
Any ideas?
Portrait
Landscape
I am using the Camera2 API to setup an imagecapture fragment. I only want to use the camera in portrait mode. So i have set this line in the manifest in the fragment's parent activity:
android:screenOrientation="portrait"
Which locks the camera preview to portrait. However, the image aspect is just wrong. When the image is captured, there is no issues with the aspect, and the image looks as it should, but is still not in full screen. I suspect the camera output is stretched to fill the screen in my preview. How do i make both the preview and the captured image fill the entire screen and keep its aspect ratio like Snapchat does it?
I have been using the Google sample as my reference, and changed the AutoFitTextureView to match_parent in the XML layout file.
this is how it looks in normal portrait
and this is how it looks when i rotate the phone and is still in portrait mode
AutoFillTextureView attempts to keep the aspect ratio correct, but if you're changing its layout parameters, it may not be able to.
Do things work correctly if you don't make it 'match_parent'?
In general, Android UI elements will fill themselves with the input data, so you need to set the View's size to the right aspect ratio to avoid stretching.
For anyone who has been facing this issue like I was and if you have been using the google sample from before Jun 2017, then tweaking a line in your AutoFitTextureView should fix the preview's aspect ratio. It's as simple as changing "<" to ">" which you can see here.
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.
:)
I am Using a onCLick over a button to capture an image but when we see the preview it is upside down in vertical mode where as when the same preview is seen through horizontal preview renders correctly.
Please let me know what tweaks are necessary to readjust the preview.
You have to take into account, that camera preview image origin is on top right corner if in portait mode, and axes are swapped - and it does not depend on phone orientation. You will have to flip image to display it in portrait mode properly.
take a look at
android.hardware.Camera.setDisplayOrientation
http://developer.android.com/reference/android/hardware/Camera.Parameters.html
and
android.hardware.Camera.Parameters.setRotation
http://developer.android.com/reference/android/hardware/Camera.html