繁体   English   中英

纵向模式下的Android Landscape VideoView

[英]Android Landscape VideoView in portrait mode

我有一个活动,该活动应该以横向显示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>

(活动本身必须保持为纵向模式,因为设备将放置在覆盖导航和状态栏的外壳中,但是在横向模式下,它将不再覆盖它们)

我知道这不是最佳答案,但前一段时间我遇到了同样的问题,并且找到了一个非常方便的解决方法,它也可能会对您有所帮助。

尝试使用TextureView而不是VideoView,因为旋转它时,里面的内容也会旋转。

 <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并将其设置为您的视图,如下所示:

 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) {

    }
};

现在,只需将侦听器设置为您的TextureView:

 mTextureView.setSurfaceTextureListener(mTextureListener);

剩下要做的就是调用它来开始播放视频:

mMediaPlayer.start();

奖金:如果您想进行更复杂的调整,例如调整视频宽高比,则可以查看此库以获取更多详细信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM