调整LANDSCAPE或PORTRAIT中视频视图的大小

时间:2018-05-16 23:42:18

标签: java android-studio video fullscreen android-videoview

我是android studio的初学者,我需要你的帮助 所以我创建了一个视频播放器应用程序,但我对智能手机的方向有问题 如果你可以帮助我在两种情况下调整视频视图的大小(LANDSCAPE或PORTRAIT),那么有必要全屏保留视频 非常感谢你

我的代码

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

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        Toast.makeText(getBaseContext(),"wa9fa",Toast.LENGTH_SHORT).show();
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
   else if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
        Toast.makeText(getBaseContext(),"na3sa",Toast.LENGTH_SHORT).show();
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }


    VideoView videoView = (VideoView)findViewById(R.id.videoView);
 String path = "android.resource://" + getPackageName() + "/" + R.raw.track01;
    videoView.setVideoURI(Uri.parse(path));

    MediaController mediaController = new MediaController(this);
    mediaController.setMediaPlayer(videoView);
    mediaController.setAnchorView(videoView);
    videoView.setMediaController(mediaController);

    videoView.start();
}

0 个答案:

没有答案