Make a video in TextureView format (parts of it are outside (not visible)) using MediaPlayer

I am using MediaPlayer to play videos in TextureView. TextureView has a fixed size, and video sizes vary. It plays the video, but the problem is that parts of the video are outside and the video does not scale to fit the texture.

The black rectangles + photos (video) are TextureView. The red box is the actual video, I drew it to show the problem.

Thus, it only displays part of the video and does not show the rest.

I want the whole video to be visible and keep the original zoom ratio.

Thanks.

enter image description here

// The class implements SurfaceTextureListener // Set TextureView to MediaPlayer m_TextureView.setSurfaceTextureListener(this); @Override public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) { m_MediaPlayer = new MediaPlayer(); m_MediaPlayer.setSurface(new Surface(surfaceTexture)); } // Play video m_MediaPlayer.reset(); m_MediaPlayer.setDataSource(videoFilePath); m_MediaPlayer.prepare(); m_MediaPlayer.start(); 
+6
source share

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


All Articles