3

I'm using a VideoView for streaming (using Vitamio library)
problem is that in landscape orientation,is not fit screen.
I want to make my application only in landscape.

enter image description here

Here is what i have tried :

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>

I would like the video to fill the whole screen like the youtube app does.
Thank you for any help you can provide.

Emad
  • 588
  • 1
  • 9
  • 22

2 Answers2

2

Pleasy try adding fullscreen flags direct to 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);,
    ...

For more http://developer.android.com/reference/android/view/Window.html

Maybe you can try one of these display options:

 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);

The second param means the aspect ratio of video and will be autodetected if 0. Refer this: https://github.com/yixia/VitamioBundle/blob/master/vitamio/src/io/vov/vitamio/widget/VideoView.java

Christian
  • 76
  • 2
0

Easiest option would be to get RelativeLayout and call setSystemUiVisibility on it with View.SYSTEM_UI_FLAG_FULLSCREEN as flag.

Give Id (e.g. videoViewContainer) to RelativeLayout and add following lines:

setContentView(R.layout.videoview);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
RelativeLayout mVidContainer = (RelativeLayout) findViewById(R.id.videoViewContainer);
    mVidContainer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);

For more info, refer this link: https://developer.android.com/training/system-ui/status.html

Tejas Pawar
  • 690
  • 8
  • 16
  • Does not work ? Is it still showing status bar? What is the android sdk version ? – Tejas Pawar Jan 30 '16 at 18:16
  • Unfortunately not. I dont want hide the status bar...! The problem is that the VideoView does not fill whole screen – Emad Jan 30 '16 at 19:07
  • 1
    From image attached, I can see that the video is filling up whole screen except left and bottom margin. And you have written free for personal space there. Can you please explain the problem in detail? – Tejas Pawar Jan 30 '16 at 19:34
  • The problem is exactly that left and bottom margin.You are right :D I edited the image. // I'm using [Genymotion Emulator](https://www.genymotion.com/) and "free for personal use" is a watermark for unregistered user :D – Emad Jan 30 '16 at 19:57
  • Try changing layout_width and layout_height of RelativeLayout to match_parent. – Tejas Pawar Jan 30 '16 at 20:27
  • Try changing layout_width and layout_height of all views in your layout to match_parent. But this stretch your video if the video is not of correct resolution. – Tejas Pawar Jan 31 '16 at 07:56