我的活动布局如下所示。基本上,我在左侧有一个列表视图菜单和两个视频视图,我根据用户单击的菜单项在这两个视频视图之间切换。
<?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 保留在顶部,只有图库隐藏。有小费吗?如果您需要任何其他信息,请告诉我。谢谢!
EDIT:这是我在 onCreate() 中选择菜单项的 if 语句。希望这会有所帮助。当我单击position==1,然后单击position==2时,图库消失了,但archived_video_view仍然暂停,所以我只能看到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();
}
}
});
VideoView 是 SurfaceView。它们的工作原理是有效地将窗口弹出到硬件帧缓冲区。但只有一个这样的硬件帧缓冲区,您试图在两个 SurfaceView 中显示,并使用两个 MediaPlayer 写入。因此,当尝试处理多个 SurfaceView 时,可能会出现许多渲染错误,并且此类错误在不同设备之间不会一致。
最简单的答案是不要这样做。将每个 VideoView 隔离到单独的 Activity 中,或者重建您的布局,以便您可以共享单个视频视图。
下一个最简单的答案是不要同时进行。在两个视频视图之间切换时,请先删除一个视频视图(将其从视图层次结构中完全删除),然后再激活另一个视频视图。也许在两者之间使用 ImageView 占位符来保持 UI 在用户进行此类切换时相对一致。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)