2015-12-04 70 views
0

我試圖在我的應用程序中顯示圖像和視頻。爲此,我正在使用RecyclerView。圖像正在顯示,但視頻不顯示。該視頻完全下載,但它不在OnPreparedListenerVideoView內。如果我只使用VideoView視頻正在播放....請提出一些解決方案....謝謝。 (如果有人想看到的代碼,我將發佈)內部滾動視圖(ScrollView/RecyclerView/ListView)視頻不在播放。

我以前TextureViewSurfaceView還,我得到同樣的問題,這些觀點太...

這是scrollViewVideoView樣本示例。

str = "http://files.parsetfss.com/13e1c98b-895f-401e-83f3-7bf9b944001d/tfss-e199dd99-2564-4092-9df8-4b279ca2e7d0-video.mp4"; 

Ion.with(context) 
      .load(str) 
      .progress(new ProgressCallback() { 
       @Override 
       public void onProgress(long downloaded, long total) { 
        System.out.println("" + downloaded + "/" + total); 
        Log.d("TAG", downloaded + "/" + total); 
       } 
      }) 
      .write(fileCache.getFile(str)) 
      .setCallback(new FutureCallback<File>() { 
       @Override 
       public void onCompleted(Exception e, File file) { 
        // download done... 
        Log.d("TAG", file.getAbsolutePath()); 
        // do stuff with the File or error 
        videoUri = Uri.fromFile(file); 

        videoView2.setVideoURI(videoUri); 
        videoView2.requestFocus(); 
        videoView2.setOnPreparedListener 
          (new MediaPlayer.OnPreparedListener() { 
           @Override 
           public void onPrepared(final MediaPlayer mp) { 
            Log.d("TAG", " mp4 Done ready to play "); 
            videoView2.start(); 
            mp.setLooping(true); 
            mp.setVolume(0, 0); 
            videoView2.setOnTouchListener(new View.OnTouchListener() { 
             @Override 
             public boolean onTouch(View v, MotionEvent event) { 
              Log.d("TAG", " Volume "); 
              if (abc) { 
               mp.setVolume(0, 0); 
               Log.d("TAG", " Volume 0 "); 
               abc = false; 
              } else { 
               mp.setVolume(1, 1); 
               Log.d("TAG", " Volume 1 "); 
               abc = true; 
              } 
              return false; 
             } 
            }); 

           } 
          } 

          ); 
       } 
      }); 


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/scrollView" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
tools:context="blpacademy.videotestwithscrollandwithout.VideoView_with_scroll"> 

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    > 

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


    </LinearLayout> 
     </ScrollView> 

更新:

我試着用ListViewVideoView太....它也沒有工作....

我所滾動的觀點(ListView/RecyclerView內思考/ ScrollView)視頻(VideoView)不在播放....如果播放(TextureView/SurfaceView)視圖不滾動...

+0

發佈相關代碼! –

+0

你可能想看看:http://stackoverflow.com/a/10161316/295004和Grafika的DoubleDecode活動https://github.com/google/grafika/ –

+0

嗨,@MorrisonChang我檢查了答案,那工作,但在我的情況下,在任何滾動查看視頻不播放....任何想法1 –

回答

1

我所有的實驗我知道這裏面的任何滾動視圖(ListView/RecyclerView/ScrollView)如果要播放視頻(videoView/TextureView/SurfaceView),那麼你不能使用wrap_contentmatch_parent的寬度&高度之後。您必須將靜態或動態值分配給視頻。然後,視頻將在滾動視圖上工作。

<VideoView 
    android:id="@+id/videoView2" 
    android:layout_width="250dp" 
    android:layout_height="300dp" 
/> 
+0

你有同樣的工作示例? –

+0

我沒有得到U,例如什麼? –

+1

我試過它也行不通 –

0

帶有高度/寬度wrap-content或match-content的ScrollView裏面的VideoView會給你意想不到的結果。它不會正確地獲得高度和寬度。

解決方案:
要麼你提供了這樣的高度和寬度在佈局XML的固定數量:

<VideoView 
    android:id="@+id/videoView" 
    android:layout_width="256dp" 
    android:layout_height="256dp" 
/> 

或者設置高度和寬度videoView在運行時是這樣的:

videoView.setDimension(256,256);