2012-12-29 62 views
1

我用vitamio庫播放rtsp。 儘管我的代碼上有videoView.start();,但在完成緩衝後,視頻開始播放一分鐘!完成緩衝後,Android視頻開始播放一分鐘

但是如果我在緩衝完成後改變方向,視頻立即開始播放! 我有下面的代碼,我知道改變方向調用此方法:

@Override 
public void onConfigurationChanged(Configuration newConfig) { 
    if (videoView != null) 
     videoView.setVideoLayout(VideoView.VIDEO_LAYOUT_SCALE, 0); 
    super.onConfigurationChanged(newConfig); 
} 

但我不知道是什麼讓視頻開始,我無法迫使它開始播放(緩衝完成後立即)以任何其他方式改變方向。請幫助...

回答

0

我經歷過,當VideoView的維數爲0時,視頻將無法播放。 確保您設置了初始尺寸。

此外,我會嘗試設置佈局從開始: videoView.setVideoLayout(VideoView.VIDEO_LAYOUT_SCALE, 0);

我會接受oncVideoSizeChanged回調例如,

public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { 

      FrameLayout.LayoutParams vLayout = (FrameLayout.LayoutParams) mSurfaceView.getLayoutParams(); 
      vLayout.width = getWindowManager().getDefaultDisplay().getWidth(); 
      vLayout.height = getWindowManager().getDefaultDisplay().getHeight(); 

      float aspectRatio = (float) width/height; 
      float screenRatio = (float) vLayout.width/vLayout.height; 
      float topMargin = 0, leftMargin = 0; 

      if (screenRatio < aspectRatio) 
       topMargin = (float) vLayout.height 
         - ((float) vLayout.width/aspectRatio); 
      else if (screenRatio > aspectRatio) 
       leftMargin = (float) vLayout.width - (vLayout.height * aspectRatio); 

      vLayout.setMargins((int) leftMargin, (int) topMargin, 0, 0); 
      mSurfaceView.setLayoutParams(vLayout); 
     } 
+0

請告訴我如何設置初始尺寸後設定的尺寸。這應該在XML還是Java文件中完成?此外,從一開始就設置佈局並沒有幫助。 –

+0

通常情況下,我們會在收到onVideoSizeChanged回調後設置尺寸。我已經更新了答案,假設videoview位於FrameLayout裏面 –

+0

謝謝你的代碼,但它沒有解決問題。我調試了我的代碼,發現視頻實際上開始播放,但在Looper.Class中停止再次緩衝,通過減少緩衝區大小,它可以比以前更快地啓動。 @florianpilz –

相關問題