Skip to content

Instantly share code, notes, and snippets.

@raultm
Created September 16, 2012 17:03
Show Gist options
  • Select an option

  • Save raultm/3733246 to your computer and use it in GitHub Desktop.

Select an option

Save raultm/3733246 to your computer and use it in GitHub Desktop.

Revisions

  1. raultm revised this gist Sep 16, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion StretchVideoView.java
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    package mobi.kinetica.vegenat.catalogo.utils;
    package com.raulete.dev.stretchvideoview.utils;

    import android.content.Context;
    import android.util.AttributeSet;
  2. raultm revised this gist Sep 16, 2012. 2 changed files with 36 additions and 0 deletions.
    21 changes: 21 additions & 0 deletions VideoView onMesaure method.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    //Log.i("@@@@", "onMeasure");
    int width = getDefaultSize(mVideoWidth, widthMeasureSpec);
    int height = getDefaultSize(mVideoHeight, heightMeasureSpec);
    if (mVideoWidth > 0 && mVideoHeight > 0) {
    if ( mVideoWidth * height > width * mVideoHeight ) {
    //Log.i("@@@", "image too tall, correcting");
    height = width * mVideoHeight / mVideoWidth;
    } else if ( mVideoWidth * height < width * mVideoHeight ) {
    //Log.i("@@@", "image too wide, correcting");
    width = height * mVideoWidth / mVideoHeight;
    } else {
    //Log.i("@@@", "aspect ratio is correct: " +
    //width+"/"+height+"="+
    //mVideoWidth+"/"+mVideoHeight);
    }
    }
    //Log.i("@@@@@@@@@@", "setting size: " + width + 'x' + height);
    setMeasuredDimension(width, height);
    }
    15 changes: 15 additions & 0 deletions VideoView wrapped by RelativeLayout.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    <?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/videoViewRelative"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    </VideoView>

    </RelativeLayout>
  3. raultm revised this gist Sep 16, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions StretchVideoView.java
    Original file line number Diff line number Diff line change
    @@ -14,8 +14,8 @@ public StretchVideoView(Context context, AttributeSet attrs) {
    }

    public StretchVideoView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    }
    super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
  4. raultm created this gist Sep 16, 2012.
    25 changes: 25 additions & 0 deletions StretchVideoView.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    package mobi.kinetica.vegenat.catalogo.utils;

    import android.content.Context;
    import android.util.AttributeSet;
    import android.widget.VideoView;

    public class StretchVideoView extends VideoView {
    public StretchVideoView(Context context) {
    super(context);
    }

    public StretchVideoView(Context context, AttributeSet attrs) {
    super(context, attrs);
    }

    public StretchVideoView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
    }
    }