Last active
October 29, 2015 16:47
-
-
Save JSBerrocoso/e60613d5da6fbcb7eea4 to your computer and use it in GitHub Desktop.
AutofitVideoView: More info : http://stackoverflow.com/questions/4434027/android-videoview-orientation-change-with-buffered-video/4452597#4452597
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class VideoViewCustom extends VideoView { | |
private int mForceHeight = 0; | |
private int mForceWidth = 0; | |
public VideoViewCustom(Context context) { | |
super(context); | |
} | |
public VideoViewCustom(Context context, AttributeSet attrs) { | |
this(context, attrs, 0); | |
} | |
public VideoViewCustom(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
} | |
public void setDimensions(int w, int h) { | |
this.mForceHeight = h; | |
this.mForceWidth = w; | |
} | |
@Override | |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | |
//setMeasuredDimension(mForceWidth, mForceHeight); | |
// For not setDimension onConfigurationChange | |
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | |
getHolder().setFixedSize(getMeasuredWidth(), getMeasuredHeight()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class VideoViewCustom extends VideoView { | |
private int mForceHeight = 0; | |
private int mForceWidth = 0; | |
public VideoViewCustom(Context context) { | |
super(context); | |
} | |
public VideoViewCustom(Context context, AttributeSet attrs) { | |
this(context, attrs, 0); | |
} | |
public VideoViewCustom(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
} | |
public void setDimensions(int w, int h) { | |
this.mForceHeight = h; | |
this.mForceWidth = w; | |
} | |
@Override | |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | |
Log.i("@@@@", "onMeasure"); | |
setMeasuredDimension(mForceWidth, mForceHeight); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onConfigurationChanged(Configuration newConfig) { | |
super.onConfigurationChanged(newConfig); | |
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { | |
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); | |
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); | |
questionVideo.setDimensions(displayHeight, displayWidth); | |
questionVideo.getHolder().setFixedSize(displayHeight, displayWidth); | |
} else { | |
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); | |
questionVideo.setDimensions(displayWidth, smallHeight); | |
questionVideo.getHolder().setFixedSize(displayWidth, smallHeight); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment