Android - rendering the same video in multiple views

I have a media data source and I play on media using android MediaPlayer .

How to display video output from MediaPlayer into several views in the same Activity , are there alternative ways to do this?

I want a part of the media image to be displayed in two different views without reading several times from the data source.

Current code:

 TextureView mTextureView1; TextureView mTextureView2; mTextureView1.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() { @Override public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { mMediaPlayer = new MediaPlayer(AppActivity.this); try { mMediaPlayer.setDataSource(getApplicationContext(), Uri.parse(path)); } catch (IOException e) { e.printStackTrace(); } mMediaPlayer.setSurface(new Surface(surface)); mMediaPlayer.setLooping(true); mMediaPlayer.prepareAsync(); mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mp.start(); } }); } 
+5
source share
1 answer

You are currently playing TextureView, which takes frames in a SurfaceTexture and then renders them to the View UI layer.

One approach is to create your own SurfaceTexture to get frames, and then use OpenGL ES to render frames as you like. For example, see the action "texture from the camera" in Grafika . It can position, rotate and scale the input from the camera; you can easily change this to get input from MediaPlayer, and double render the texture on SurfaceView.

If you want to display it in different Views, you can set up a couple of TextureViews and render them. Use one EGL context with a different EGL surface for each view.

+2
source

All Articles