2011-08-10 84 views
0

我開發的應用程序,用於播放視頻..播放視頻是這裏的代碼..安卓播放寬屏視頻

public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
WindowManager.LayoutParams.FLAG_FULLSCREEN); 

    setContentView(R.layout.videoview); 
    Intent i = getIntent(); 
    Bundle extras = i.getExtras(); 
    filename = extras.getString("videofilename"); 
    mVideoView = (VideoView)findViewById(R.id.videoview); 

    path=filename; 
    if (path == "") { 
     // Tell the user to provide a media file URL/path. 
     Toast.makeText(
       ViewVideo.this, 
       "Please edit VideoViewDemo Activity, and set path" 
         + " variable to your media file URL/path", 
       Toast.LENGTH_LONG).show(); 

    } else { 

      mVideoView.setVideoPath(path); 
      mc = new MediaController(this); 
      mVideoView.setMediaController(mc); 
      mVideoView.requestFocus(); 
      mVideoView.bringToFront(); 
      mVideoView.start(); 

    } 
} 

下面是XML代碼

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 
    <VideoView android:id="@+id/videoview" 
      android:layout_width="fill_parent" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentBottom="true" 
      android:layout_height="fill_parent"> 
     </VideoView> 
     </RelativeLayout> 

的問題是,當我嘗試播放寬屏幕16:9視頻。它在全屏顯示它,字符出現擠壓。我需要用寬屏格式(視頻上方和下方的兩個水平黑條)播放。 有什麼建議嗎?

+0

您是否也可以發佈您的XML佈局? – theisenp

+0

我編輯了包含xml的代碼..你能否幫我在這裏.. – Farhan

+0

可能你需要爲VideoView設置佈局參數。我已經爲其中一個stackoverflow帖子上的視頻回放放置了一個Activty的代碼。可以參考http://stackoverflow.com/questions/6977382/videoview-in-eclipse-not-playing-on-phone/6977770#6977770 – Shash316

回答

1

這是related question

好像你正迫使視頻與屏幕的四邊對齊使用

android:layout_alignParentRight="true" 
android:layout_alignParentLeft="true" 
android:layout_alignParentTop="true" 
android:layout_alignParentBottom="true" 

這是擺脫視頻的縱橫比。請嘗試將它放在LinearLayout中:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:gravity="center"> 

    <VideoView android:id="@+id/videoview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 

</LinearLayout> 
+0

先生,我試過了..它是部分工作..實際上問題是..水平條現在出現在底部;但是,當我刪除標題欄以使其可以出現在視頻上方時,整個視頻就會向上推。你有什麼想法嗎? – Farhan

+0

嘗試在LinearLayout中添加一個android:gravity =「center」字段。我在我的答案中更新了XML。如果你願意,你可以刪除標題欄,但你不需要。 – theisenp

+0

謝謝你這麼多先生..它的工作..真的很感謝你的幫助.. – Farhan

1

嘗試在垂直linearLayout中使用MediaViewer。

像這樣的東西(從我的頭頂,所以不要絕對地信任它):

<LinearLayout android:layout_height="match_parent" 
    android:layout_width="match_parent" android:weightSum="9" 
    android:orientation="vertical"> 
    <VideoView android:layout_height="0dp" android:layout_width="0dp" 
     android:layout_weight="6" /> 
</LinearLayout> 

這應該填滿屏幕的垂直面積的2/3。

根據需要調整weightSum和layout_weight。

希望這會有所幫助!

+0

可以請詳細說明一個更.. ..其實我想動態調整視頻播放器的視頻..有一些視頻不是寬屏,有一些視頻是寬屏,寬高比爲16:9與遮罩(水平視頻下方和上方的黑條),我想我的應用程序動態設置此..你知道是否有任何方式來設置視頻的寬高比?請回復 – Farhan

+0

我不知道有一種方法可以設置縱橫比...您必須調整VideoView的大小。您應該可以使用提供的代碼執行此操作,只需使用LayoutParams將VideoView的layout_weight更改爲您所需的任何內容即可。 – Codeman