2013-04-25 123 views
1

我在VideoView中播放視頻在本地和url路徑中播放視頻時的問題

從SD卡播放時,它會在全屏幕中顯示正確的寬度和高度。當我嘗試從服務器播放時,視頻寬度變小,視頻重新調整大小。

如何以原始尺寸和全屏播放視頻?

+0

什麼是你所使用的服務器?你確定你的服務器沒有進行任何編碼或調整視頻文件的大小。通過比較原始文件和從服務器下載的文件,檢查文件的大小。 – 2013-04-25 13:06:54

回答

0

看看的documentation並實現類似下面的代碼的onPrepared方法:

//prepare the video 
public void onPrepared(MediaPlayer mp) {   
    progressBarWait.setVisibility(View.GONE); 

    //First get the size of the video 
    int videoWidth = player.getVideoWidth(); 
    int videoHeight = player.getVideoHeight(); 
    float videoProportion = (float) videoWidth/(float) videoHeight; 

    //get the size of the screen 
    int screenWidth = getWindowManager().getDefaultDisplay().getWidth(); 
    int screenHeight = getWindowManager().getDefaultDisplay().getHeight(); 
    float screenProportion = (float) screenWidth/(float) screenHeight; 

    //Adjust 
    LayoutParams lp = surfaceViewFrame.getLayoutParams(); 
    if (videoProportion > screenProportion) { 
     lp.width = screenWidth; 
     lp.height = (int) ((float) screenWidth/videoProportion); 
    } else { 
     lp.width = (int) (videoProportion * (float) screenHeight); 
     lp.height = screenHeight; 
    } 
    surfaceViewFrame.setLayoutParams(lp); 

    if (!player.isPlaying()) { 
     player.start();   
    } 
    surfaceViewFrame.setClickable(true); 
} 
+0

謝謝。請告訴我們需要爲「player」和「surfaceViewFrame」傳遞哪個參考。 – basheer 2013-04-25 13:04:02

+0

播放器是您的MediaPlayer對象,而surfaceViewFrame是[SurfaceView](http://developer.android.com/reference/android/view/SurfaceView.html)。 – StarPinkER 2013-04-25 13:14:46

+0

請給我任何編碼播放視頻在Surfaceview.now我玩videoview – basheer 2013-04-25 13:21:22