Video view resizing to video size

Asked

Viewed 488 times

1

I have a problem in my application, in the app I make a sequence of videos, but at the time I did the structure and inserted the video (it is not of much graphic quality so the app does not get too big) Videoview kind of resized and was very small, Does anyone have any idea how I can fix this? Yeah I don’t care if the video gets ugly if it gets pixelated.

<?xml version="1.0" encoding="utf-8"?>

<VideoView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/VV1"
    android:layout_weight="1" />

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_weight="0">




    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/btnVoltar"
        android:id="@+id/button2"
        android:layout_weight="2" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/btnAvanca"
        android:id="@+id/button3"
        android:layout_weight="2" />
</LinearLayout>

  • could post the xml code of this Videoview?

2 answers

0

Oops, all right!? a while ago I had this same problem... but it was with images.

My problem was this: I had a imageView which occupied a ratio of 2x1, within a LinearLayout, but according to the size of the cell phone was messed up (small, large, distorted...), so my solution was this: I put the imageView to occupy the entire space of LinearLayout, and I set the linear sizes, in my case it was 100% wide, and 28% high. so the image was in the correct ratio:

    LinearLayout layout = (LinearLayout) findViewById(R.id.linearBanner);
    ViewGroup.LayoutParams parametros = layout.getLayoutParams();
    Display display = getWindowManager().getDefaultDisplay();
    parametros.height = ((display.getHeight() * 28) /100); //nesse trecho do código eu defini que ele ia sempre ocupar 28% da tela, mas no seu caso mude para display.getHeight(), pegando 100% de altura e 100% de largura.
    parametros.width = display.getWidth();
    layout.setLayoutParams(parametros);

In your case, put the VideoView within a linear, and set this code above (this linearBanner will be your linear parent, which will occupy 100% of the screen, or as much as you want).

Hugs.

0

Good morning, I think it is possible to do this with Videoview but another option is to use Surfaceview: xml:

 < SurfaceView
        android:id="@+id/surface_view1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical" />

Activity:

public class MainActivity extends AppCompatActivity implements MediaPlayer.OnErrorListener, MediaPlayer.OnPreparedListener,SurfaceHolder.Callback {

private MediaPlayer mediaPlayer;
private SurfaceView surfaceView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    surfaceView = (SurfaceView)findViewById(R.id.surface_view1);
   SurfaceHolder surfaceHolder = surfaceView.getHolder();
    surfaceHolder.addCallback(this);
    MediaPlayer mediaPlayer   = new MediaPlayer();
    Uri videoUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.big_buck_bunny);

    try {
        mediaPlayer.setDataSource(this,   videoUri);
        mediaPlayer.prepare();
    } catch (IOException e) {
        e.printStackTrace();
    }

    mediaPlayer.setOnErrorListener(this);
    mediaPlayer.setOnPreparedListener(this);
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}



@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
    Log.d(TAG, "onError() called with: " + "mp = [" + mp + "], what = [" + what + "], extra = [" + extra + "]");
    return false;
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    mediaPlayer.setDisplay(holder);
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {

}

@Override
public void onPrepared(MediaPlayer mp) {
    mp.start();
}
  • Diniz, thanks, but I’d like to use the video view anyway, you have no idea how it does not?

  • I have, I have, but I don’t have the code, but here it is: http://stackoverflow.com/questions/11310764/videoview-full-screen-in-android-application.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.