1

I am trying to play a video in android using Video View, But the video is not completely stretching to fit the screen instead the video view is stretching and its showing black empty screen on either side of the Screen

I want the video to be strecthed without considering any aspect ratio.

any help on this

Thanks & Nagendra

XMl:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" >

    <VideoView android:id="@+id/myvideoview"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" />

</RelativeLayout>

Code:

setContentView(R.layout.main);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
videoPlayer = (VideoView) findViewById(R.id.myvideoview);
String uri = "android.resource://" + getPackageName() + "/" + R.raw.video;

videoPlayer.setVideoURI(Uri.parse(uri)); 
videoPlayer.setMediaController(new MediaController(this));
videoPlayer.requestFocus();
videoPlayer.setVisibility(0);
videoPlayer.start();

This is the code i am using to play a video

Thanks for your reply

Nitzan Tomer
  • 155,636
  • 47
  • 315
  • 299
Nagendra
  • 11
  • 1
  • 2

2 Answers2

2

A trick you can do is put the VideoView inside a RelativeLayout and add the parameters:

android:layout_alignParentRight="true" android:layout_alignParentLeft="true" 
android:layout_alignParentTop="true" android:layout_alignParentBottom="true"

This will "stretch" the video to be fullscreen. If the video AspectRatio is good enough you will have a very good result

Alexander Vogt
  • 17,879
  • 13
  • 52
  • 68
Ignacio Barrea
  • 121
  • 2
  • 5
0

Use fill_parent for layout_width and layout_height in the xml of VideoView:

<VideoView android:layout_height="fill_parent"
android:layout_width="fill_parent" android:id="@+id/VideoView"></VideoView>
Dinesh Sharma
  • 11,533
  • 7
  • 42
  • 60