我有一个媒体数据源,我正在使用 android 播放媒体MediaPlayer
。
如何MediaPlayer
在同一个视图中显示来自多个视图的视频输出Activity
,有没有其他方法可以做到这一点?
我希望媒体的视频部分以两个不同的视图呈现,而无需从数据源多次读取。
当前代码:
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();
}
});
}