如何解决如何使用ExoPlayer在屏幕外渲染然后在屏幕上渲染
我在Xamarin Android上使用ExoPlayer。
我想要什么:
- 通过代码创建ExoPlayer并在屏幕外加载视频
- 将第一帧渲染到屏幕外并暂停
- 在屏幕外捕获第一帧的位图
- 将位图加载到屏幕上的ImageView
- 隐藏ImageView并在屏幕上恢复视频播放
exoPlayer = new SimpleExoPlayer.Builder(UI.Player.Context).Build();
var listener = new PlayerListener();
listener.init(ExoPlayer_RenderedFirstFrame); // my callback method
exoPlayer.AddListener(listener);
exoPlayer.AddVideoListener(listener);
// Draw offscreen in surface
GLES30.GlEnable(GLES11Ext.GlTextureExternalOes);
GLES30.GlGenTextures(1,_textures,0);
GLES30.GlBindTexture(GLES11Ext.GlTextureExternalOes,_textures[0]);
GLES30.GlBindTexture(GLES11Ext.GlTextureExternalOes,0);
surfaceTexture = new SurfaceTexture(_textures[0],true);
surface = new Surface(surfaceTexture);
exoPlayer.SetVideoSurface(surface);
exoPlayer.Prepare(buildMediaSourceNew(videoUri));
exoPlayer.PlayWhenReady = true;
private void ExoPlayer_RenderedFirstFrame()
{
exoPlayer.PlayWhenReady = false;
usePixelCopy(surface,pixelCopyCallback);
}
public void pixelCopyCallback(Bitmap bitmap)
{
UI.Player.Context.RunOnUiThread(() =>
{
var drawable = new BitmapDrawable(UI.Player.Context.Resources,bitmap);
drawable.SetAntiAlias(true);
imageFrame.SetImageDrawable(drawable);
});
}
上面的代码正在工作。但是,如何将渲染重定向到UI? Surface不是UI控件。我找不到将现有的Surface或SurfaceTexture添加到UI的方法:-(
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。