gpt4 book ai didi

类似于 Youtube 应用的 Android VideoView 方向

转载 作者:太空宇宙 更新时间:2023-11-03 11:25:26 25 4
gpt4 key购买 nike

我正在尝试在我的应用中复制 Youtube 应用在播放视频时所做的事情。

纵向模式:仅使用 40% 的屏幕显示视频,其余部分显示有关视频的信息。

横向模式:以全屏模式显示视频和窗口。

我在 stack overflow 和其他论坛中看到了很多关于这个主题的话题,但似乎没有一个适合我。目前我的 videoplayeractivity 有 android:configChanges="keyboardHidden|orientation|screenSize"并且我已经使用以下代码覆盖了 onConfigurationChanged 事件:

@Override
public void onConfigurationChanged(Configuration config)
{
super.onConfigurationChanged(config);

if (config.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
// requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

}
else
{
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

}
}

这不会将应用程序置于全屏状态,如果我取消对 requestwindowfeature 的注释,它将崩溃,因为“在添加内容之前必须调用 requestFeature()”。后来我尝试删除 onConfigurationChanged 事件和我尝试过的 onCreate 事件:

@Override
public void onCreate(Bundle savedInstanceState)
{
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_video);

但是,如果我在纵向上开始 Activity 然后翻转到横向,则会在 com.android.internal.policy.impl.PhoneWindow$PanelFeatureState.onRestoreInstanceState(PhoneWindow.java:3527) 处出现 NullPointerException 崩溃。有什么建议吗?

最佳答案

全屏显示:

video_layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/video"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />

Activity :

  @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

并支持像 youtube 应用程序这样的方向更改: Toggling fullscreen & orientation like YouTube

关于类似于 Youtube 应用的 Android VideoView 方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16471564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com