6

I am playing a video in a surfaceView. When I scale the surfaceView its coordinated are properly scaled but the video content which is being played is not.

I am scaling view by using ViewHelper.setscaleX method. I tried several things but was unable to scale video..if I change the params then video is properly scaled. But that makes the transition slow. Please see the snapshot of initial video and final video (after scaling).

initial video with surface view scale 1

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

sanjeev
  • 1,343
  • 3
  • 16
  • 28
  • 2
    "if I change the params then" params? what params? – pskink Sep 11 '14 at 12:50
  • LayoutParams of the view, changing width and height of view. – sanjeev Sep 11 '14 at 12:59
  • For an example of resizing a SurfaceView surface, see AspectFrameLayout in Grafika (https://github.com/google/grafika/blob/master/src/com/android/grafika/AspectFrameLayout.java). It's used there to adjust the size to match the aspect ratio for video playback, but should be adaptable. – fadden Sep 12 '14 at 06:17

4 Answers4

1

Solved it. Use TextureView instead of SurfaceView. Animations doesn't work on surfaceview. Use this link to play video using textureView : Playing video on TextureView

Community
  • 1
  • 1
sanjeev
  • 1,343
  • 3
  • 16
  • 28
1

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

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

mbonnin
  • 6,893
  • 3
  • 39
  • 55
  • 1
    `layoutParams` consume much more CPU compared to `setScale...` so animation will be in very low fps – oleynikd May 21 '16 at 22:35
1

Add a transparent view above the surfaceview like relative layout and add scalegesture detector on that transparent view and when scaling occurs just perform that scaling on surfaceview or textureview.

Let's suppose that transparent view is named videoview.

Videoview.setOnClicklistner();

And when scaling is performed implement that scalefactor to surfaceview like

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

It will work smoothly

Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
  • hey the setScale method is always scaling taking the centre , is there any way we can change that to the centre focus of screen – Anjani Mittal Jan 07 '19 at 09:06
0

If you have to stick with SurfaceView because you're using a third party library or whatnot, a workaround would be to scale it down using the scale animation and AFTER the animation has finished, update the layoutparams of the SurfaceView by giving the the correct size and position. It's not perfect, but should be good for those who have no other choice.

mco
  • 1,809
  • 15
  • 31
  • You'd need also to set the scale back to 1, otherwise the view will appear with the correct width/height set by layout params, but scaled to the scale set after the animation. – Giulio Piancastelli Oct 19 '18 at 12:27