VideoView 不适合横向屏幕(使用 Vitamio 库)
VideoView is not fit screen in landscape(using Vitamio library)
我正在使用 VideoView 进行流式传输 (使用 Vitamio library)
问题是在横向上,不适合屏幕。
I want to make my application only in landscape.
这是我尝试过的方法:
MainActivity :
public class ActivityMain extends Activity {
private String path = "http://hw14.asset.aparat.com/aparat/video/1d7288ace5ce9cc812f6cf5b99d2b8b62642090-360p__87605.mp4";
private VideoView mVideoView;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (!LibsChecker.checkVitamioLibs(this))
return;
setContentView(R.layout.videoview);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mVideoView = (VideoView) findViewById(R.id.buffer);
mVideoView.setVideoPath(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
// optional need Vitamio 4.0
mediaPlayer.setPlaybackSpeed(1.0f);
}
});
}
}
layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#FFFFFF"
android:gravity="center"
android:foregroundGravity="center">
<io.vov.vitamio.widget.CenterLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:clickable="false">
<io.vov.vitamio.widget.VideoView
android:id="@+id/buffer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
android:clickable="false" />
</io.vov.vitamio.widget.CenterLayout>
</RelativeLayout>
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.app">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/MyTheme">
<activity
android:name="io.vov.vitamio.activity.InitActivity"
android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize|smallestScreenSize"
android:launchMode="singleTop"
android:theme="@android:style/Theme.NoTitleBar"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity android:name=".ActivityMain"
android:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我希望视频像 youtube 应用程序一样填满整个屏幕。
感谢您提供的任何帮助。
最简单的选择是获取 RelativeLayout 并在其上使用 View.SYSTEM_UI_FLAG_FULLSCREEN 作为标志调用 setSystemUiVisibility。
将 Id(例如 videoViewContainer)提供给 RelativeLayout 并添加以下行:
setContentView(R.layout.videoview);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
RelativeLayout mVidContainer = (RelativeLayout) findViewById(R.id.videoViewContainer);
mVidContainer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
有关详细信息,请参阅此 link:
https://developer.android.com/training/system-ui/status.html
请尝试将全屏标志直接添加到 WindowManager
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (!LibsChecker.checkVitamioLibs(this))
return;
setContentView(R.layout.videoview);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
this.getWindow().addFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);,
...
更多http://developer.android.com/reference/android/view/Window.html
也许您可以尝试以下显示选项之一:
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_ORIGIN, 0);
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_SCALE, 0);
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH, 0);
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_ZOOM, 0);
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_FIT_PARENT, 0);
第二个参数表示视频的宽高比,如果为0将被自动检测。
参考这个:https://github.com/yixia/VitamioBundle/blob/master/vitamio/src/io/vov/vitamio/widget/VideoView.java
我正在使用 VideoView 进行流式传输 (使用 Vitamio library)
问题是在横向上,不适合屏幕。
I want to make my application only in landscape.
这是我尝试过的方法:
MainActivity :
public class ActivityMain extends Activity {
private String path = "http://hw14.asset.aparat.com/aparat/video/1d7288ace5ce9cc812f6cf5b99d2b8b62642090-360p__87605.mp4";
private VideoView mVideoView;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (!LibsChecker.checkVitamioLibs(this))
return;
setContentView(R.layout.videoview);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mVideoView = (VideoView) findViewById(R.id.buffer);
mVideoView.setVideoPath(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
// optional need Vitamio 4.0
mediaPlayer.setPlaybackSpeed(1.0f);
}
});
}
}
layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#FFFFFF"
android:gravity="center"
android:foregroundGravity="center">
<io.vov.vitamio.widget.CenterLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:clickable="false">
<io.vov.vitamio.widget.VideoView
android:id="@+id/buffer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
android:clickable="false" />
</io.vov.vitamio.widget.CenterLayout>
</RelativeLayout>
manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.app">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/MyTheme">
<activity
android:name="io.vov.vitamio.activity.InitActivity"
android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize|smallestScreenSize"
android:launchMode="singleTop"
android:theme="@android:style/Theme.NoTitleBar"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity android:name=".ActivityMain"
android:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我希望视频像 youtube 应用程序一样填满整个屏幕。
感谢您提供的任何帮助。
最简单的选择是获取 RelativeLayout 并在其上使用 View.SYSTEM_UI_FLAG_FULLSCREEN 作为标志调用 setSystemUiVisibility。
将 Id(例如 videoViewContainer)提供给 RelativeLayout 并添加以下行:
setContentView(R.layout.videoview);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
RelativeLayout mVidContainer = (RelativeLayout) findViewById(R.id.videoViewContainer);
mVidContainer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
有关详细信息,请参阅此 link: https://developer.android.com/training/system-ui/status.html
请尝试将全屏标志直接添加到 WindowManager
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (!LibsChecker.checkVitamioLibs(this))
return;
setContentView(R.layout.videoview);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
this.getWindow().addFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);,
...
更多http://developer.android.com/reference/android/view/Window.html
也许您可以尝试以下显示选项之一:
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_ORIGIN, 0);
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_SCALE, 0);
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_STRETCH, 0);
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_ZOOM, 0);
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_FIT_PARENT, 0);
第二个参数表示视频的宽高比,如果为0将被自动检测。 参考这个:https://github.com/yixia/VitamioBundle/blob/master/vitamio/src/io/vov/vitamio/widget/VideoView.java