簡體   English   中英

縱向方向的Android VideoView全屏

[英]Android VideoView Full Screen in Portrait Orientation

請以全屏模式以全屏模式觀看視頻。我想在應用程序的啟動頁面上以全屏顯示視頻。

這是我的代碼。 我有一個視頻視圖可以填充寬度,但是高度只是屏幕中間的一部分。我希望視頻視圖可以覆蓋整個寬度和高度。

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"/>

好吧,我認為您必須編輯清單文件並在其中添加一些代碼:

“我希望這行得通”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM