Android VideoView同时播放2个视频

发布于 2024-09-04 05:26:15 字数 174 浏览 6 评论 0原文

我正在尝试在另一个视频视图之上播放 videoview 。第一个视频视图已暂停,而第二个视频视图正在播放。它似乎可以工作,但屏幕上没有出现第二个视频(尽管我听到了音频并看到了通常出现在顶部的控件)。我假设这是某种订单问题。有什么想法。顺便说一句,我可以毫无问题地在主视频视图之上显示其他视图并使视频填充背景。

I am trying to play a videoview on top of another video view. The first video view is paused, while the second is playing. It appears to work but no second video appears on the screen (though I hear the audio and see the controls that would normally appear on top). I am assuming this is some sort of order issue. Any thoughts. By the way, I have no problem displaying other views on top of the main video view and having the video fill the background.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

浮生未歇 2024-09-11 05:26:15

这是行不通的 - VideoView 是特殊的,因为它在普通视图中“打”了一个洞,以允许直接访问显示像素(或者,用 Android 术语来说,“Surface” - VideoView 是 SurfaceView 的子类) )。您不能将两个 SurfaceView 叠加在一起 ​​- 第一个获取像素的 SurfaceView(Surface)将“拥有”它。 (请参阅 SurfaceHolder.Callback.surfaceCreated() / surfaceDestroyed())

SurfaceView 之上的其他视图可以工作,因为框架将在 Surface 之上组合普通视图的显示位。它无法对另一个 VideoView(即 SurfaceView)执行此操作,因为没有任何内容可组合。

That won't work - the VideoView is special in the sense that it 'punches' a hole in the normal Views to allow direct access to the display pixels (or, in android terms, the 'Surface' - VideoView is a subclass of SurfaceView). You cannot layer two SurfaceViews on top of eachother - the first one that grabs the pixels (the Surface) will 'own' it. (see SurfaceHolder.Callback.surfaceCreated() / surfaceDestroyed())

Other Views on top of a SurfaceView do work, because the framework will compose the display bits of normal Views on top of the Surface. It cannot do that with another VideoView (i.e. a SurfaceView) because there is nothing to compose.

岁月如刀 2024-09-11 05:26:15
<VideoView android:id="@+id/videoView1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"/>
<VideoView android:id="@+id/videoView2" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"/>

当 videoView2 开始播放时,videoView1 的可见性将不可见。
然后您可以在需要时使其可见。

<VideoView android:id="@+id/videoView1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"/>
<VideoView android:id="@+id/videoView2" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"/>

when videoView2 starts playing setvisibilty of videoView1 invisible.
then you can make it visible when you need.

梦幻的心爱 2024-09-11 05:26:15

使用Thread来控制两个视频

Use Thread to control both video

春庭雪 2024-09-11 05:26:15

我不知道这目前是否有帮助,但我设法得到了与你想要的类似的东西......

我需要在 SurfaceView 之上嵌套一个 VideoView ;只要它们不 100% 重叠就可以工作。 (我的意思是,我的 SurfaceView 是整个屏幕,而 VideoView 只是屏幕的一小部分)

问题是 - 因为您无法组合 SurfaceView,所以第一个获取像素的就是将要显示的像素。直观性将驱使您在 XML 中不太重要的视图之后对优先视图进行 Z 排序 - 但正如我之前所说,第一个获取像素的视图会保留,因此请确保首先定义较小的视图,然后再定义将其与较大的覆盖。

这将导致较小的(在我的情况下预览视图)获取所述 X * Y 像素,然后“背景”表面视图(根据 XML 应该位于其顶部)占据其余部分。并忽略较小的表面。

我不太确定如何处理这两个组件的事件,因为我只需要在这两个视图中播放流,而不会对这两个组件生成的任何类型的点击/事件做出反应,但如果您遵循此操作,则可能会发生这种情况路线 - 较大的视图将拦截在较小视图区域中进行的所有点击(因为根据 XML,它位于顶部),因此也许您必须在创建时以编程方式将其移动到顶部。

希望有帮助。

编辑:
虽然...它就像只工作一次。这确实是一项正在进行的工作。从任何活动返回后,我无法采取任何措施来阻止更大的视野夺取一切:/

I don't know if this is helpful at the moment, but I managed to get something similar to what you want...

I needed to nest a VideoView on top of a SurfaceView; as long as they don't overlap 100% it can work. (what i mean is, my surfaceview is the whole screen and videoview is just a small portion of the screen)

The thing is - since you can't compose SurfaceViews, the first one to grab the pixels is the one that will be shown. Intuitiveness will drive you to Z-order your prioritized view AFTER the less-important one in the XML - but as I've said previously, the first one to grab the pixels stays, so make sure you define the smaller view FIRST, and then overlay it with the bigger one.

This will result in such behaviour that the smaller (in my case preview view) acquires the said X * Y pixels, and then the 'background' surfaceview (which is supposed to be on top of it according to the XML) takes up the rest and ignores the smaller surface.

I'm not too sure about handling events from those two though as I only have to play streams in those two views and not react to any kind of clicks/events generated by those two components, but it might be expected that if you followed this route - the bigger view will intercept all clicks made in the smaller view area (because it's on top according to the XML) so maybe you have to programatically move it on top as well upon creation.

Hope it helps.

EDIT:
Although... it like it just works once. It's a work in progress really. Upon returning from any activity, there's nothing i can do to prevent the bigger view claiming everything :/

甜心 2024-09-11 05:26:15

你可以在视频视图 b 上添加视频视图 a,就像这样,

     parentview.removeview(a);
    parentview.removviewe(b);
    parentview.addview(a);
    parentview.addview(b);
parentview.invalidate();

Ti 为我工作。我希望它能有所帮助。

you can add videoview a on top videoview b,like this,

     parentview.removeview(a);
    parentview.removviewe(b);
    parentview.addview(a);
    parentview.addview(b);
parentview.invalidate();

Ti's work for me. I hope it can helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文