一个视屏被另一个视屏挡住了[英] One videoview blocked by another videoview

本文是小编为大家收集整理的关于一个视屏被另一个视屏挡住了的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我的活动布局如下所示.基本上我在左边的ListView菜单和两个VideoViews我在根据用户点击的菜单项之间切换.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout   
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_system_status"
    android:title="@string/system_status"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:layout_weight="4">
        <ListView
        android:id="@+id/list_video_feed"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        </ListView>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linear_layout_live_video"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:layout_weight="1">

        <VideoView 
        android:id="@+id/video_view" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linear_layout_video_gallery"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:layout_weight="1">

        <Gallery 
        android:id="@+id/gallery"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />

        <VideoView 
        android:id="@+id/archived_video_view" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />

    </LinearLayout>

</LinearLayout>

在我的代码中,如果我想从没有画廊的视图中播放视频,我隐藏了另一个.

linearLayoutVideoGallery.setVisibility(GONE);
linearLayoutLiveVideo.setVisibility(VISIBLE);
playVideo();

问题是Archived_video_View停留在顶部,只有画廊隐藏.有小费吗?如果您需要任何其他信息,请告诉我.谢谢!

编辑:以下是选择InCreate()中选择菜单项的语句.希望这将有所帮助.当我单击位置== 1然后发布== 2时,画廊已经消失,但archived_video_view仍然暂停,所以我只能看到video的顶部slive of video _view曾经是.

          lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
                if (position==1) { //video gallery list item has been pressed
                    vvLive.stopPlayback();
                    linearLayoutLiveVideo.setVisibility(GONE);
                    linearLayoutVideoGallery.setVisibility(VISIBLE);
                    playArchivedVideo();

                }

                else if (position == 2) { //live video list item has been pressed
                    vvArchive.stopPlayback();
                    linearLayoutVideoGallery.setVisibility(GONE);
                    linearLayoutLiveVideo.setVisibility(VISIBLE);
                    playLiveVideo();
                }
            }
          });

推荐答案

视频视图是surfaceviews.他们通过有效地突出窗口到硬件帧缓冲来工作.但只有一个这样的硬件帧缓冲区,您正在尝试在两个SurfaceViews中显示,以及用两个MediaPlayers写入.因此,尝试拼凑多个SurfaceView时,存在许多渲染错误,并且在不同的设备之间不会一致地存在.

最简单的答案是不要这样做的.将每个VideoView隔离为单独的活动,或重建您的布局,以便您可以共享一个视频视图.

下一个最简单的答案是不同时进行的.在两个视频视图之间切换时,请在激活另一个视频视图之前删除一个(从视图层次结构中完全删除它).也许使用ImageView占位符,以保持UI相对一致,因为使用使得这种交换机.

本文地址:https://www.itbaoku.cn/post/102426.html

问题描述

My activity layout is shown below. Basically I have a listview menu on the left and two videoviews that I switch between depending on which menu item the user clicks.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout   
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_system_status"
    android:title="@string/system_status"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:layout_weight="4">
        <ListView
        android:id="@+id/list_video_feed"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        </ListView>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linear_layout_live_video"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:layout_weight="1">

        <VideoView 
        android:id="@+id/video_view" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linear_layout_video_gallery"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:layout_weight="1">

        <Gallery 
        android:id="@+id/gallery"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />

        <VideoView 
        android:id="@+id/archived_video_view" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />

    </LinearLayout>

</LinearLayout>

In my code, if I want to play a video from the view without the gallery, I hide the other.

linearLayoutVideoGallery.setVisibility(GONE);
linearLayoutLiveVideo.setVisibility(VISIBLE);
playVideo();

The problem is that the archived_video_view stays on top and only the gallery hides. Any tips? Let me know if you need any additional information. Thanks!

EDIT: Here is my if statement for choosing the menu items inside onCreate(). Hopefully this will help. When I click position==1 and then postion==2, the gallery is gone but the archived_video_view is still there paused so I can only see the top sliver of video_view where the gallery used to be.

          lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
                if (position==1) { //video gallery list item has been pressed
                    vvLive.stopPlayback();
                    linearLayoutLiveVideo.setVisibility(GONE);
                    linearLayoutVideoGallery.setVisibility(VISIBLE);
                    playArchivedVideo();

                }

                else if (position == 2) { //live video list item has been pressed
                    vvArchive.stopPlayback();
                    linearLayoutVideoGallery.setVisibility(GONE);
                    linearLayoutLiveVideo.setVisibility(VISIBLE);
                    playLiveVideo();
                }
            }
          });

推荐答案

VideoViews are SurfaceViews. They work by effectively popping a window through to the hardware framebuffer. But there is only one such hardware framebuffer that you are trying to show in both SurfaceViews, as well as write to with both MediaPlayers. Thus, there are numerous rendering errors that can occurs when trying to juggle multiple SurfaceViews, and such errors will not be consistent between different devices.

The simplest answer is don't do it. Isolate each VideoView into separate Activities, or reconstruct your layout so that you can share a single video view.

The next simplest answer is don't do it simultaneously. When switching between two video views, remove one (completely remove it from the View hierarchy) before activating another. Maybe use an ImageView placeholder in between to keep the UI relative consistent as the use makes such a switch.