2011-08-10 3 views
0

비디오 재생을위한 응용 프로그램을 개발했습니다. 비디오를 재생하는 코드는 여기에 있습니다.android : 와이드 스크린 비디오 재생

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

android : gravity = "center"필드를 LinearLayout에 추가 해보십시오. 내 대답에 XML을 업데이트했습니다. 원하는 경우 제목 표시 줄을 제거 할 수는 있지만 사용자는 필요하지 않습니다. – theisenp

+0

감사합니다. 너무 많이 ... 선생님 .. 도와 주셔서 정말 감사드립니다. – Farhan

1

verticalLayout에서 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의 크기를 조정해야합니다. 제공된 코드를 사용하여이 작업을 수행 할 수 있어야합니다. VideoPlay의 layout_weight를 LayoutParams에 필요한 것으로 변경할 수 있습니다. – Codeman