一个videoview拦截另一videoview [英] One videoview blocked by another videoview

查看:99
本文介绍了一个videoview拦截另一videoview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的活性布局如下所示。基本上我在左边列表视图菜单和两个videoviews,我这取决于哪个菜单项,用户点击之间切换。

 < XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / activity_system_status
    机器人:标题=@字符串/ system_status
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=横向>

    <的LinearLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:方向=垂直
        机器人:layout_weight =4>
        <的ListView
        机器人:ID =@ + ID / list_video_feed
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT>
        < / ListView控件>
    < / LinearLayout中>

    <的LinearLayout
        机器人:ID =@ + ID / linear_layout_live_video
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:方向=垂直
        机器人:layout_weight =1>

        < VideoView
        机器人:ID =@ + ID / video_view
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:layout_gravity =中心
        />
    < / LinearLayout中>

    <的LinearLayout
        机器人:ID =@ + ID / linear_layout_video_gallery
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:方向=垂直
        机器人:layout_weight =1>

        <画廊
        机器人:ID =@ + ID /画廊
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        />

        < VideoView
        机器人:ID =@ + ID / archived_video_view
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        />

    < / LinearLayout中>

< / LinearLayout中>
 

在我的code,如果我想打从视图视频没有画廊,我躲在另一个。

  linearLayoutVideoGallery.setVisibility(GONE);
linearLayoutLiveVideo.setVisibility(可见);
的playVideo();
 

的问题是,在archived_video_view停留在顶端和仅画廊皮等。任何提示吗?让我知道如果你需要任何额外的信息。谢谢!

修改:这是我的if语句选择的onCreate里面的菜单项()。希望这会有所帮助。当我点击的位置== 1,然后现在的位置== 2,画廊走了,但archived_video_view仍然存在暂停,所以我只能看到video_view那里的画廊曾经是顶部的条子。

  lv.setOnItemClickListener(新OnItemClickListener(){
            公共无效onItemClick(适配器视图<>母公司视图中查看,
                INT位置,长的id){
                如果(位置== 1){//视频库列表项已经pressed
                    vvLive.stopPlayback();
                    linearLayoutLiveVideo.setVisibility(GONE);
                    linearLayoutVideoGallery.setVisibility(可见);
                    playArchivedVideo();

                }

                否则,如果(位置== 2){//视频直播列表项已经pressed
                    vvArchive.stopPlayback();
                    linearLayoutVideoGallery.setVisibility(GONE);
                    linearLayoutLiveVideo.setVisibility(可见);
                    playLiveVideo();
                }
            }
          });
 

解决方案

VideoViews是SurfaceViews。他们的工作,通过对硬件的帧缓冲区有效地弹出一个窗口。但是,只有一个这样的硬件帧缓冲,您正试图在这两个SurfaceViews显示,以及写有两个MediaPlayers。因此,也有可以试图处理多个SurfaceViews时,会发生大量的渲染错误,这样的错误也不会不同的设备之间一致的。

最简单的回答是不这样做。隔离每个VideoView为单独的活动,或重建你的布局,使您可以共享一个单一的视频查看。

接下来简单的答案是不同时做。当两个视频视图之间切换,激活另一个之前,删除一个(完全是从视图层次结构中删除)。也许使用ImageView的占位符之间保持UI相对一致的使用使得这种开关。

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.

这篇关于一个videoview拦截另一videoview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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