2011-04-15 116 views
2

我的活動佈局如下所示。基本上我有一個左側的列表視圖菜單和兩個視頻切換,這取決於用戶點擊哪個菜單項。一個videoview被另一個videoview屏蔽

<?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停留在頂部,只有畫廊隱藏。有小費嗎?如果您需要任何其他信息,請告知我。謝謝!

編輯:這是我的if語句,用於選擇onCreate()內的菜單項。希望這會有所幫助。當我點擊位置== 1,然後位置== 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(); 
       } 
      } 
      }); 
+0

您是否完全確定您正在使用正確的ID來獲取linearLayoutVideoGallery和linearLayoutLiveVideo視圖? – slund 2011-04-15 21:26:08

+0

是的。當我點擊視頻庫,然後點擊直播視頻時,頂部的水平畫廊就會隱藏起來,我只能看到現場視頻播放的那條小條,因爲存檔視頻仍處於前臺。我用switch語句添加了一些額外的代碼。謝謝。 – yellavon 2011-04-18 14:47:32

回答

4

VideoViews是SurfaceViews。他們通過有效地將窗口彈出到硬件幀緩衝區來工作。但是,您只有一個這樣的硬件幀緩衝區,您試圖在兩個SurfaceView中顯示,以及使用兩個MediaPlayers寫入。因此,嘗試玩弄多個SurfaceView時可能會出現大量渲染錯誤,並且這些錯誤在不同設備之間不一致。

最簡單的答案是不要這樣做。將每個VideoView分隔成單獨的活動,或重建您的佈局,以便共享單個視頻視圖。

下一個最簡單的答案是不要同時做。在兩個視頻視圖之間切換時,請在激活另一個視圖視圖之前刪除一個(從View層次結構中完全刪除它)也許在兩者之間使用ImageView佔位符,以保持用戶界面相對一致,因爲用戶可以進行這種切換。