gpt4 book ai didi

android - 在 Android VideoView 上绘制叠加层(HUD)?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:02:49 26 4
gpt4 key购买 nike

我有一个绘制 HUD 的自定义 View :

HUD

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<VideoView
android:id="@+id/videoView1"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<com.widgets.HUD
android:id="@+id/hud"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

</FrameLayout>
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.hud_fragment, container, false);

frameLayout = (FrameLayout) view.findViewById(R.id.frameLayout);

hudWidget = (HUD) view.findViewById(R.id.hudWidget);

videoView = (VideoView) view.findViewById(R.id.videoView1);
videoView.setVideoURI(Uri.parse("http://88.150.210.138:5001/spor"));
videoView.start();

frameLayout.removeView(hudWidget);
frameLayout.addView(hudWidget);
hudWidget.bringToFront();

return view;
}

一旦视频开始播放,我就在我的 VideoView 上播放一个 RTSP 流,它看起来像这样:

Video On HUD

如何强制 HUD 在 VideoView 之上绘制? HUD 扩展了 SurfaceView

项目

  • 我要添加 VideoView 的项目是 DroidPlanner您可以尝试克隆并查看问题。 (需要手动添加 VideoView,因为它不在存储库中)。

最佳答案

我找到了您问题的答案:VideoView on top of SurfaceView SurfaceView 和 VideoView 都是表面 View ,旧版本的 Android 不支持重叠它们,但从 2.0 开始可用。

你需要做什么:

  1. 将像素格式设置为透明,让视频在界面中闪耀

hudWidget.getHolder().setFormat(PixelFormat.TRANSPARENT);

  1. 将 HUD 表面设置为媒体覆盖。

hudWidget.setZOrderMediaOverlay(true);

  1. 创建一个新表面并将其设置为播放视频的 MediaPlayer 的显示。

有一个拉取请求,您可以在其中尝试这些。 https://github.com/arthurbenemann/droidplanner/pull/247

带来解决方案的线程:https://groups.google.com/forum/?fromgroups#!msg/android-developers/nDNQcceRnYA/ps9wTBfXIyEJ

关于android - 在 Android VideoView 上绘制叠加层(HUD)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17899474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com