Stretch to fill VideoView, aspect ratio of VideoView
Asked Answered
H

3

19

I try to stretch video in aim to fill videoview. The target is to create view that in device look like the first pic (like it look in layout preview).

Most of the answers to this questions refer to this link.

I tried this but I still didn't fill video view.

This my layout code :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="@drawable/search_gren_screen">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/go_back"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:onClick="onclick"
            android:text="Try again" />

        <Button
            android:id="@+id/back_to_pick_song"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Select another song" 
            android:onClick="onclick" />

        <Button
            android:id="@+id/btn_continue"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:onClick="onclick"
            android:text="Amazing, continue!" />
    </LinearLayout>

    <FrameLayout 
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
    <VideoView 
        android:id="@+id/videoView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_gravity="center" />
    </FrameLayout>
</LinearLayout>

Here you have a preview of my declared layout:

enter image description here

However, the result on the device is different:

enter image description here

Hodden answered 24/4, 2013 at 11:50 Comment(3)
Your layout code is okay to fulfill your need. But keep in mind that VideoView will shrink/stretch with respect to the Video playing in it.Gisborne
ok, so i need change the aspect ratio of the media recorder mean to add mMediaRecorder.setVideoSize(640, 480); i try this and it'n work ... ???Hodden
check this answer https://mcmap.net/q/331820/-videoview-to-match-parent-height-and-keep-aspect-ratioTolmach
D
43

Try to make your outer layout a relative layout and put the VideoView inside that.

Something like:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/trim_container"
     android:layout_width="match_parent"
     android:layout_height="match_parent" >

     <LinearLayout
          android:id="@+id/buttonContainer"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal" >

     <Button
          android:id="@+id/go_back"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_gravity="center"  
          android:layout_weight="1"
          android:onClick="onclick"
          android:text="Try again" />

     <Button
          android:id="@+id/back_to_pick_song"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_weight="1"
          android:text="Select another song" 
          android:onClick="onclick" />

    <Button
          android:id="@+id/btn_continue"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:layout_weight="1"
          android:onClick="onclick"
          android:text="Amazing, continue!" />
  </LinearLayout>

  <VideoView
     android:id="@+id/VideoView"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_alignParentLeft="true"
     android:layout_alignParentRight="true"
     android:layout_alignParentBottom="true"
     android:layout_below="@id/buttonContainer"/>
</RelativeLayout>
Dessiatine answered 24/4, 2013 at 12:0 Comment(2)
It fuc..ing workssss!! This is the easiest way to achieve this thing. I have been wasting a lot of time trying to achieve this. Thanks a lot!!!!!!Monochromat
i wasted hours trying to make that happen, Thanks a lot manJorgenson
S
2

video view should be inside to the Relative Layout. Here is an example given below. In my case, it works very fine with a FullScreen Button.

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="3"
            android:id="@+id/videoVIewLinId"
            android:layout_gravity="center"
            android:gravity="center"
            android:scaleType="fitXY"

            >
                <VideoView
                    android:layout_alignParentTop="true"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentStart="true"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:id="@+id/videoViewId"
                    />


                <ImageView
                    android:id="@+id/fullScreenBtnIdOnlineMedia"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_action_full_screen"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentBottom="true"
                    android:layout_marginEnd="10dp"

                    />

        </RelativeLayout>
Stoecker answered 11/2, 2020 at 5:56 Comment(0)
M
0

The fill_parent method doesn't work for me.

Finally I use this library, works great!

https://github.com/dmytrodanylyk/video-crop

Mammiemammiferous answered 17/8, 2020 at 17:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.