2013-03-18 136 views
4

我有一個片段,允許用戶從混合列表中選擇視頻和圖像內容。選擇多媒體項目時,根據媒體類型的不同,顯示會在ImageViewVideoView之間切換。問題是,當用戶選擇一個視頻時,只播放音頻,並且VideoView保持黑色。Android:片段內的VideoView只播放音頻,不顯示視頻

這是用來顯示視頻的碼:(多數在底部的代碼是試錯,看是否缺少東西來解決這個問題)

mainVideo.setVisibility(View.VISIBLE); 
mainImage.setVisibility(View.INVISIBLE); 
getActivity().getWindow().setFormat(PixelFormat.TRANSLUCENT); 
parent.showLoader(R.string.buffering); 

mainVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 
    @Override 
    public void onPrepared(MediaPlayer mp) { 
     parent.hideLoader(); 
     mainVideo.requestFocus(); 
     mainVideo.start(); 
    } 
}); 
mainVideo.setOnErrorListener(new MediaPlayer.OnErrorListener() { 
    @Override 
    public boolean onError(MediaPlayer mp, int what, int extra) { 
     showErrorMessage(R.string.multimedia_load_failed, R.string.please_try_again_later); 
     parent.hideLoader(); 
     return true; 
    } 
}); 
Uri video = Uri.parse(mm.url); 
mainVideo.setMediaController(new MediaController(parent)); 
mainVideo.setKeepScreenOn(true); 
mainVideo.bringToFront(); 
mainVideo.setDrawingCacheEnabled(true); 
mainVideo.setActivated(true); 
mainVideo.setEnabled(true); 
mainVideo.setVideoURI(video); 

Log.i(TAG, "Loading video: " + video.toString()); 

parent是一個參考。擁有像showLoader和諸如此類的一些便利的功能活性)

這裏是我的佈局:

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

     <FrameLayout 
      android:layout_width="275dp" 
      android:layout_height="275dp" 
      android:layout_gravity="center_horizontal" 
      android:padding="1dp" 
      android:background="@color/light_grey"> 
      <ImageView 
       android:id="@+id/mm_main_image" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="@color/black" 
       android:scaleType="fitXY"/> 
      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 
       <VideoView 
        android:id="@+id/mm_main_video" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_alignParentTop="true" 
        android:layout_alignParentBottom="true" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentRight="true"> 
       </VideoView> 
      </RelativeLayout> 
     </FrameLayout> 

     <TextView 
      android:id="@+id/mm_index_count" 
      android:layout_width="wrap_content" 
      android:layout_height="20dp" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:layout_margin="@dimen/large_padding" 
      android:layout_gravity="center_horizontal" 
      android:textColor="@color/white"/> 

     <HorizontalScrollView 
      android:id="@+id/mm_horizontal_scroll" 
      android:layout_height="110dp" 
      android:layout_width="wrap_content"> 
      <LinearLayout 
       android:id="@+id/mm_media_list" 
       android:layout_height="match_parent" 
       android:layout_width="wrap_content"> 
       <!-- Content filled dynamically --> 
      </LinearLayout> 
     </HorizontalScrollView> 
    </LinearLayout> 
</ScrollView> 

我期待所有通過StackOverflow和最近兩天的網絡,但無法在任何地方找到解決此問題的解決方案。任何幫助表示讚賞。

所有的視頻(和圖像)是遙遠的,他們不在Android設備上。

+0

這似乎幾乎相同http://stackoverflow.com/questions/13864118/android-videoview-control-is-not-displaying-video-only-audio-is-played但唉,沒有好的答案那裏 – 2013-09-04 15:06:13

回答

5

嘗試刪除在XML中定義的任何背景顏色。它可能覆蓋視頻視圖。

+0

這解決了我的問題。多麼奇怪的「功能」。「謝謝。 – Gi0rgi0s 2015-11-29 21:53:45

+0

顯然有些「混淆背景」的意思。 *嘆* – 2017-02-10 17:46:38

相關問題