video to fit screen in android
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 MediaContr开发者_JAVA技巧oller(this));
videoPlayer.requestFocus();
videoPlayer.setVisibility(0);
videoPlayer.start();
This is the code i am using to play a video
Thanks for your reply
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
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>
精彩评论