Posts

Showing posts from February, 2012

Android's VideoView doesn't always stretch video.

Creating a full screen simple video player on Android 2.4.x(GingerBread), I've been annoyed by the problem that VideoView doesn't always stretch videos to full screen(keeping aspect ratio). Reading VideoView's code, I finally found a solution to this. Point is to call getHolder().setFixedSize in onMeasure. class StretchVideoView(context:Context, attr:AttributeSet) extends VideoView(context, attrib) { def measure(measureSpec:Int):Int = { val specMode = View.MeasureSpec.getMode(measureSpec) View.MeasureSpec.getSize(measureSpec) } override def onMeasure(widthMeasureSpec:Int, heightMeasureSpec:Int) { val (w,h) = (measure(widthMeasureSpec), measure(heightMeasureSpec)) getHolder().setFixedSize(w,h) super.onMeasure(widthMeasureSpec, heightMeasureSpec) } } By the way, the above code is written in Scala, so please write in Java if you're not Scala guy (Usually not).