How to make TextureView play video with round corn

2020-04-12 08:49发布

I managed to play video with TextureView and MediaPlayer on Android. I did it like this: I created a Surface with SurfaceTexture:

    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int w, int h)
{
    mSurface = new Surface(surfaceTexture);
    ...
    ...
}

Attatch the Surface to MediaPlayer:

    try
{
    mMediaPlayer.setDataSource(mPlayUrl);
    mMediaPlayer.setSurface(mSurface);
    ...
    ...
}

That is OK, but not enough for me. I expect that the TextureView to be with round corners and look like a bubble(with an angle), look at the picture below: effect I expect

I found an article(Round video corners on Android) which is very helpful, but the author chose GLSurfaceView and only implemented round corners. I believe that TextureView is also suitable for implementing my effect, SurfaceTexure processing is the key.But I am not familiar with opengl, Who can give me some advices?

2条回答
放我归山
2楼-- · 2020-04-12 09:33

I know it's late reply, but if anyone still struggle to finds solution below sample may help. https://github.com/developer-anees/android-round-camera2video-preview

Try this sample. It display camera preview in circle. Basically it use FrameLayout as parent to display Textureview in circle.

查看更多
ら.Afraid
3楼-- · 2020-04-12 09:33

Given that your background is a solid color, you can easily achieve this effect with a mask. If you have any sort of background it wouldn't work though.

查看更多
登录 后发表回答