同时在一个VideoView中播放两个视频 [英] Play two videos in one VideoView at the same time

查看:614
本文介绍了同时在一个VideoView中播放两个视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是关于在两个单独的视频视频中播放两个单独视频的问题。



我被要求查看是否可以创建一个一个VideoView的活动。当用户打开活动时,将要求他们选择基本视频,然后选择第二个视频。两个视频将同时在一个VideoView中播放,但基本视频的alpha为255,第二个视频的alpha为150。



对于测试,手机上的视频文件将会执行。



此时,我只能创建一个在VideoView中播放单个视频的活动。



我以为如果我创建了一个自定义的VideoView类,我可以覆盖onDraw功能,以某种方式从第二个视频中抓取视频帧,应用alpha,然后在第一个VideoView的画布,但我不知道从哪里开始。



我对此过程的其他关注是在一个VideoView中一次播放两个视频的内存量以及应用Alpha所需的处理,然后无缝重画,而不影响视频的性能或播放。



我不知道从哪里开始,或者如何最好地接近这个,如果可能的话,希望对任何方法或对象使用一些指导。



我正在开发一个演示应用程序,使用Eclipse在Android 2.2系统上显示客户端。此时,由于演示手机运行的是Android 2.2,我并不打算瞄准任何更高的系统。

解决方案

我不完全确定为什么要使用这样的VideoView。 VideoView只使用一个MediaPlayer,并使用它来同步一个视频,可能需要通过相同的VideoView子类在相同的表面上渲染两个MediaPlayers的非常kludgey实现。



查看源代码,了解MediaPlayer如何在VideoView内部呈现视频以及MediaController如何控制播放。你可能会在那里闯入那里,让两个MediaPlayers立刻指向同一个VideoView / SurfaceView。或者,您可以将 MediaPlayer 以处理多个数据源。



做这些事情之一是与VideoView和MediaPlayer所构建的一样,性能将会受到很大的打击。 p>

如果使用VideoView并不是一个困难的要求,那么我的建议是使用现有的视频库,如 ffmpeg ,这将比重写基础媒体类更容易,更具性能(请注意:使用ffmpeg将需要NDK,我建议使用现有的ffmpeg包装器以节省时间)。



一旦将ffmpeg添加到您的项目中,应用次要视频为 OverlayVideoFilter 将是相当容易的,应该允许你在顶层的一个视频(尽管控制播放可能对您而言是一个挑战)。



正确的路径可能取决于复合视频想要做什么(将视频导出为单个视频,控制播放等) )。


This is not a question about playing two separate videos in two separate VideoViews on the one activity.

I have been asked to see if it is possible to create an activity with a single VideoView. When the user opens the Activity, they are asked to select a base video and then select a second video. Both videos will be playing in the one VideoView at the same time, but the base video will have an alpha of 255 and the second video will have an alpha of 150.

For testing though, video files located on the phone will do.

At this time, I have only been able to create an activity that plays a single video in a VideoView.

I thought if I created a custom VideoView class I could override the onDraw function and somehow grab the video frame from the second video, apply alpha and then redraw it over the first VideoView's canvas, but I do not know where to start.

My other concern with this process is the amount of memory used to play two videos at once in the one VideoView as well as the processing required to apply the alpha and then redraw it seamlessly without affecting the performance or playback of the video.

I'm not sure where to start or how best to approach this and if possible, was hoping for some guidance as to either methods or objects to use.

I'm developing a demo application to show the client on an Android 2.2 system using Eclipse. I'm not looking to target any higher systems at this time as the demo phone runs Android 2.2.

解决方案

I'm not entirely sure why you would want to use a VideoView like that. VideoViews use only one MediaPlayer and using it to sync one video on top of another would probably require a very kludgey implementation of two MediaPlayers through the same VideoView subclass, rendering on the same surface.

Take a look at the source code to see how a MediaPlayer renders a video inside of a VideoView and how MediaController controls playback. You can probably hack around in there to have two MediaPlayers point at once to the same VideoView/SurfaceView. Alternatively you could probably subclass MediaPlayer to handle multiple data sources.

Doing either of these things is counter to what VideoView and MediaPlayer are built for, and performance is going to take a huge hit.

If using a VideoView is not a hard requirement, then my suggestion would be to use an existing video library like ffmpeg, which would be easier and more performant than rewriting base media classes (caveat: using ffmpeg will require the NDK, I suggest using an existing ffmpeg wrapper to save time).

Once ffmpeg is added to your project, applying the secondary video as an OverlayVideoFilter would be fairly easy, and should allow you to layer one video on top of the other (though controlling playback simultaneously might be a challenge left for you).

The correct path to take probably depends on what you want to do with the compound video once you get it (export the video as a single video, control playback, etc.).

这篇关于同时在一个VideoView中播放两个视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆