android 工作室中的纵向到横向视频视图和控制器重启问题

portrait to landscape Video viewand controller restart problam in android studio

我有一个 videoView,我通过 MediaController 控制它 它运行良好,但是当用户在那里更改时 phone 位置从纵向旋转到横向模式或(从横向到纵向倒置)

它将再次在视频的第一个重新开始

为了更好的理解我拍了视频请观看 观看此视频 https://www.youtube.com/watch?v=AtlzTqtc7zg&feature=youtu.be

我的xml布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <VideoView
        android:id="@+id/videoView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp" />
</LinearLayout>

我的MainActivity.class

package sirwansoft.safir.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends AppCompatActivity {
    VideoView videoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        videoView = findViewById(R.id.videoView);

        videoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.video);

        //control media
        MediaController mediaController = new MediaController(this);
        //set view with controller
        videoView.setMediaController(mediaController);
        //set Controller to view
        mediaController.setAnchorView(videoView);
        videoView.start();

    }
}

将此代码添加到您的 AndroidManifest 文件中:

<activity
    android:name="YOUR_ACTIVITY_NAME"
    android:configChanges="screenSize|orientation|keyboardHidden"
/>