mr.icetea
mr.icetea

Reputation: 2637

Exoplayer video does not scale when SurfaceView is scaled

I'm using Exoplayer library to create video player application. I'm trying to make a feature like youtube: drag video player to bottom and i will be scaled to smaller size. To do that, i have used ViewDragHelper. When player is dragging, i scale it size like this:

public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
            mTop = top;

            mDragOffset = (float) top / mDragRange;

            mVideoView.setPivotX(mHeaderView.getWidth());
            mVideoView.setPivotY(mHeaderView.getHeight());
            mVideoView.setScaleX(1 - mDragOffset / 2);
            mVideoView.setScaleY(1 - mDragOffset / 2);

            mDescView.setAlpha(1 - mDragOffset);
            requestLayout();
        } 

mVideoView is a SurfaceView, and player take SurfaceView to render it content. The SurfaceView scale correctly but it's content doesn't.

Question: how can scale SurfaceView and it's content too?

Upvotes: 2

Views: 5379

Answers (4)

linkaipeng
linkaipeng

Reputation: 503

You can use TextureView instead of SurfaceView like this:

<com.google.android.exoplayer2.ui.PlayerView
        android:id="@+id/play_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:surface_type="texture_view"/>

Upvotes: 4

mco
mco

Reputation: 1839

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 to where the scaled position is. It's not perfect, but should be good for those who have no other choice.

Upvotes: 0

Pirdad Sakhizada
Pirdad Sakhizada

Reputation: 608

It's a little late as an answer, but another solution would be to wrap the SurfaceView with a FrameLayout. Then modify the layout params or the correct properites of the FrameLayout instead of directly modifying the SurfaceView.

Note: a custom Layout can also be used and in some cases might be the better approach.

Upvotes: 0

mr.icetea
mr.icetea

Reputation: 2637

Finally, i have found a solution for my question. I used TextureView instead SurfaceView, now it worked perfect.

Upvotes: 8

Related Questions