我在Xamarin Android上使用ExoPlayer。
我想要什么:
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的方法:-(