简体   繁体   English

多个Android Surface用户-视频回放到两个SurfaceView

[英]Multiple android Surface consumers - video playback to two surfaceviews

I have this use case, where video from MediaPlayer has to be delivered to two Surface s. 我有这个用例,必须将来自MediaPlayer的视频传递到两个Surface Unfortunately, whole Android Surface API lack's of that functionality (or at least, after studying developers site, I'm unable to find it). 不幸的是,整个Android Surface API都缺少该功能(或者至少在研究开发人员站点后,我找不到它)。

I've had a simillar use case where the video was produced by a custom camera module, but after a slight modification, I was able to retrieve Bitmap from the camera so I just used lockCanvas, drawBitmap and unlockAndPost on two Surfaces. 我有一个类似的用例,其中视频是由自定义摄像头模块制作的,但是经过稍加修改后,我能够从摄像头中检索位图 ,因此我只在两个Surface上使用过lockCanvas,drawBitmap和unlockAndPost。 With MediaPlayer, I don't know how to retrieve Bitmap and keep playback with proper timing. 使用MediaPlayer,我不知道如何检索位图并以适当的时间保持播放。

Also, I've tried to use Allocation for that purpose, with one Allocation serving as USAGE_IO_INPUT, two as USAGE_IO_OUTPUT, and with ioReceive, copyFrom, ioSend methods. 另外,我尝试使用“ 分配”来实现此目的,其中一个分配用作USAGE_IO_INPUT,两个分配用作USAGE_IO_OUTPUT,并使用ioReceive,copyFrom,ioSend方法。 But it was also an dead end. 但这也是一个死胡同。 For some unknown reason, RenderScript engine is very unstable on my platform, I've had numerous errors like: 由于某些未知原因,RenderScript引擎在我的平台上非常不稳定,我遇到了许多错误,例如:

android.renderscript.RSInvalidStateException: Calling RS with no Context active.

when context passed to RenderScript.create was this from Application class, or 何时从Application类传递到RenderScript.create的上下文是此对象 ,或者

 Failed loading RS driver: dlopen failed: could not locate symbol .... falling back to default

(I've lost full log somewhere...). (我在某处丢失了完整的日志...)。 And at the end, I was not able to create proper Input Allocation type to be compatible with MediaPlayer. 最后,我无法创建合适的输入分配类型以与MediaPlayer兼容。 Due to mentioned flaws with RenderScript on my platform, I would consider this as last resort for solving this issue. 由于我平台上提到的RenderScript的缺陷,我认为这是解决此问题的最后手段。

So, in conclusion: How to play video (from mp4 file) to two Surfaces? 因此,结论是:如何将视频(从mp4文件)播放到两个Surface? This video has to be in sync. 该视频必须同步。 Also, more generic question, how to play video to #X Surface's which can be dynamically added, removed during playback? 此外,还有一个更通用的问题,如何将视频播放到#X Surface的视频中,该视频可以在播放过程中动态添加或删除?

I've resolved my issue by having multiple instances of MediaPlayer with same video file source. 我已经通过使用具有相同视频文件源的多个MediaPlayer实例解决了我的问题。 When doing basic player operations like pause/play/seek, I'm just doing them on every player. 在执行基本的播放器操作(例如暂停/播放/搜索)时,我只是在每个播放器上进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM