Android VideoView 纵向全屏

标签 android android-videoview

请帮助我在纵向模式下全屏观看视频。我想在应用程序的初始页面全屏显示视频。

这是我的代码。 我有一个填充宽度的视频 View ,但高度只是中间屏幕的一部分。我希望视频 View 填充整个宽度和高度。

public class SplashFragment extends Fragment {

public static final String TAG = SplashFragment.class.getSimpleName();
private FragmentInterface mFragmentInterface;
private VideoView mSplashVideoView;
private Uri mUri;

public SplashFragment() {
}

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    mFragmentInterface = (FragmentInterface) context;
}

@Override
public void onDetach() {
    super.onDetach();
    mFragmentInterface = null;
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mFragmentInterface.showActionBar(false);
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_splash, container, false);
    return view;
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    initView(view);
    initListener();
    playVideo();
}

@Override
public void onResume() {
    super.onResume();
    playVideo();
}

private void initView(View view) {
    mSplashVideoView = (VideoView) view.findViewById(R.id.splashVideoView);
    mUri = Uri.parse("android.resource://" + getActivity().getApplication().getPackageName() + "/" + R.raw.mylawmp4);
    mSplashVideoView.setMediaController(null);
    mSplashVideoView.setVideoURI(mUri);
}

private void initListener() {
    mSplashVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            displayScreens();
        }
    });
}

private void playVideo() {
    mSplashVideoView.setZOrderOnTop(true);
    mSplashVideoView.start();
}

private void displayScreens() {
    if (mFragmentInterface != null) {
        if (!PreferenceUtil.isLoggedIn(getActivity())) {
            mFragmentInterface.action(Constants.FragmentInterfaceConstants.ACTION_SEND_OTP, null);
        } else {
            mFragmentInterface.action(Constants.FragmentInterfaceConstants.ACTION_HOME, null);
        }
    }
}

Xml 布局如下所示

   <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/splashScreen"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <VideoView
        android:id="@+id/splashVideoView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:visibility="visible" /> </FrameLayout>

最佳答案

尝试将以下属性添加到您的 xml 布局中的 VideoView:

 <VideoView 
     android:id="@+id/splashVideoView"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_alignParentLeft="true"
     android:layout_alignParentRight="true"
     android:layout_alignParentBottom="true"
     android:layout_alignParentTop="true"/>

关于Android VideoView 纵向全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38604755/

相关文章:

android - ListViews - 如何在 API 11 之前使用 ArrayAdapter.addAll() 函数?

android - java中字符串上带点的拆分函数

android - 在 RecyclerView 适配器中显示 FragmentDialog

android - 调用 setZOrderOnTop(true) 后在 videoView 上绘制

安卓播放器WOWZA服务器RTSP码流问题

android - 播放视频时禁用Android的VideoView requestAudioFocus?

java - 使用 .getInt 时出现 NullPointerException 和应用程序崩溃 (Android)

android - SQLite建表出错

Android最简单VideoView示例无法运行

Android VideoView 不显示