Video does not scale when scaling SurfaceView

I am playing a video in a surfaceView. When I scale the surface, its coordinated ones scale correctly, but the video content that is playing is missing.

I scale the view using the ViewHelper.setscaleX method. I tried several things but could not scale the video. If I change the settings, then the video will scale correctly. But this makes the transition slow. See Snapshot of source video and final video (after scaling).

initial video with surface view scale 1

video after surfaceView is scaled. See at the bottom-right

+5
source share
4 answers

I decided. Use TextureView instead of SurfaceView. Animation does not work on the surface. Use this link to play video using texture: Play video in TextureView

+1
source

Beware that TextureView will consume more battery than SurfaceView, since it draws your video with openGL, while SurfaceView can use hardware overlays if available.

As other people said in the comments, you could achieve what you want by changing the layoutParams of your view.

+1
source

If you need to stick with SurfaceView because you are using a third-party library or something else, a workaround would be to zoom out using the zoom animation, and AFTER the animation is complete, update the layoutparams of the SurfaceView to provide the correct size and position. This is not ideal, but should be good for those who have no other choice.

0
source

Add a transparent view over the surface view, for example, a relative layout, and add a scale detector to this transparent view, and when zooming happens, just zoom over the surface or texture.

Suppose the transparent view is called videoview .

 Videoview.setOnClicklistner(); 

And when scaling is done, realize that scalefactor is a surfaceview , e.g.

 Surfaceview.setscaleX(scalefactor); Surfaceview.setscaleY(scalefactor); 

It will work smoothly

0
source

Source: https://habr.com/ru/post/1202337/


All Articles