2014-12-17 6 views
1

가로로 VideoView를 표시해야하는 활동이 있지만 활동 자체가 가로 모드가 아니어야하므로 이것이 내가 가진 것입니다.Android Landscape 가로 세로 모드의 VideoView

<activity 
     android:name=".gui.VideoPlayer" 
     android:label="@string/app_name" 
     android:launchMode="singleTask" 
     android:screenOrientation="portrait" > 
    </activity> 

<?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:orientation="horizontal" > 

    <VideoView 
     android:id="@+id/myvideoview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center" /> 

</LinearLayout> 

(장치가 탐색 및 상태 바로 커버 케이스에 넣어되기 때문에 그 자체가 세로 모드로 유지해야하지만 가로 모드에서 실 거예요 더 이상 그들을 다루 활동)

+1

나는 [질문] [1] & this [answer] [2]가 귀하의 질문에 대답 할 수 있다고 생각합니다. [1] : http://stackoverflow.com/q/4434027/2978334 [2] : http://stackoverflow.com/a/4452597/2978334 –

답변

0

나는 이것이 최적의 해답이 아니라는 것을 알고 있지만, 나는 이전에 같은 문제가 있었고, 역시 당신을 도울 수있는 매우 편리한 해결 방법을 발견했다.

VideoView 대신 TextureView를 사용하면 회전 할 때 내부의 내용도 회전하기 때문에 TextureView를 사용하십시오.

<TextureView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/my_texture_view" 
    android:rotation="90" 
    android:scaleX="1.8" 
    /> 

다음 당신이 SurfaceTextureListener를 만들고 아래와 같이보기로 설정해야합니다 :

mTextureView.setSurfaceTextureListener(mTextureListener); 

모든 : 당신의 TextureView에 리스너를 설정 해주기

TextureView.SurfaceTextureListener mTextureListener = new TextureView.SurfaceTextureListener() { 
    @Override 
    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) { 

     Surface s = new Surface(surfaceTexture); 
     try { 
     mMediaPlayer = new MediaPlayer(); 
     mMediaPlayer.setDataSource(currentPageVideoUrl); 
     mMediaPlayer.setSurface(s); 
     mMediaPlayer.prepare(); 
     }catch (Exception e){e.printStackTrace();} 
    } 

    @Override 
    public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i1) { 
    } 

    @Override 
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) { 
     return false; 
    } 

    @Override 
    public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) { 

    } 
}; 

그리고 동영상을 시작하려면 다음과 같이 호출해야합니다.

mMediaPlayer.start(); 

보너스 : 더 자세한 내용은 비디오 종횡비 조정과 같은보다 복잡한 조정을하려는 경우 You can check this library.