Полноэкранный просмотр видео в ландшафтном режиме

Я хочу сделать VideoView полноэкранным в ландшафтном режиме. Я попробовал это. Он показывает поля слева и справа. Я хочу знать, как я могу сделать VideoView полноэкранным.

Мой .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"
    android:orientation="vertical" >

    <VideoView
        android:id="@+id/videoViewN"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" />
</RelativeLayout>

person Rahul Matte    schedule 13.06.2014    source источник


Ответы (3)


Вы можете добавить тему к активности в файле манифеста:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

А для VideoView в xml измените

android:layout_height="wrap_content"

to

android:layout_height="fill_parent"

Это поможет вам добиться полноэкранного режима просмотра видео. Надеюсь, поможет.

person MysticMagicϡ    schedule 13.06.2014
comment
@RahulMatte вы также добавили android:configChanges="orientation|screenSize" в манифест? - person MysticMagicϡ; 13.06.2014
comment
Я заставляю активность открываться только в ландшафтном режиме... поэтому я думаю, что мне не нужно - person Rahul Matte; 13.06.2014
comment
Ok. Попробуйте добавить requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); эти две строки перед setContentView. @RahulMatte - person MysticMagicϡ; 13.06.2014
comment
ok..У меня уже есть эти строки после setContentView getWindow().clearFlags(WindowManager .LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); - person Rahul Matte; 13.06.2014
comment
@RahulMatte Можете ли вы проверить, работает ли это перед setContentView? - person MysticMagicϡ; 13.06.2014
comment
Давайте продолжим обсуждение в чате. - person Rahul Matte; 13.06.2014

добавление приведенных ниже кодов до того, как setContentView заработает для меня в функции onCreate. Я надеюсь, что это помогает.

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
person faraway    schedule 13.06.2014
comment
хорошо ... я узнал, что видеопросмотр отображает разрешение в соответствии с разрешением исходного файла ... Хорошо. Но могу ли я растянуть его на весь экран? Я попробовал ваш код, он не работает. - person Rahul Matte; 13.06.2014
comment
лучше сохранить соотношение сторон, в любом случае использование нижеприведенных свойств может вам помочь. android:layout_height=fill_parent android:layout_weightht=fill_parent - person faraway; 13.06.2014

Полноэкранное альбомное видео

AndroidManifext.xml (установка ориентации)

        <activity
        android:name=".Video1"
        android:screenOrientation="landscape" />

Код Video1.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Video1">

<VideoView
    android:id="@+id/videoView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent">
</VideoView>

Video1.java Code :

import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;

public class Video1 extends AppCompatActivity {

private VideoView videoView;
private MediaController mediaController;

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

    videoView = findViewById(R.id.videoView);
    String fullScreen =  getIntent().getStringExtra("fullScreenInd");
    if("y".equals(fullScreen)){
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getSupportActionBar().hide();
    }

    Uri videoUri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.YOUR_VIDEO_NAME);

    videoView.setVideoURI(videoUri);

    mediaController = new FullScreenMediaController(this);
    mediaController.setAnchorView(videoView);

    videoView.setMediaController(mediaController);
    videoView.start();
    }
}

Код FullScreenMediaControler.java:

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.MediaController;

public class FullScreenMediaController extends MediaController {

private ImageButton fullScreen;
private String isFullScreen;

public FullScreenMediaController(Context context) {
    super(context);
}

@Override
public void setAnchorView(View view) {

    super.setAnchorView(view);

    //image button for full screen to be added to media controller
    fullScreen = new ImageButton (super.getContext());

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.RIGHT;
    params.rightMargin = 80;
    addView(fullScreen, params);

    //fullscreen indicator from intent
    isFullScreen =  ((Activity)getContext()).getIntent().
            getStringExtra("fullScreenInd");

    if("y".equals(isFullScreen)){
        fullScreen.setImageResource(R.drawable.ic_fullscreen_exit);
    }else{
        fullScreen.setImageResource(R.drawable.ic_fullscreen);
    }

    //add listener to image button to handle full screen and exit full screen events
    fullScreen.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent intent = new Intent(getContext(),Video1.class);

            if("y".equals(isFullScreen)){
                intent.putExtra("fullScreenInd", "");
            }else{
                intent.putExtra("fullScreenInd", "y");
            }
            ((Activity)getContext()).startActivity(intent);
        }
    });
  }
}
person Mikhael Lauda    schedule 05.06.2018