To be able to change the View of the player depending on the rotation of the device we have to use the MediaPlayer-Class instead of the VideoView-Class.
So first you have to extend the SurfaceView and to catch the event when the size of the view is calculating. This event is called "OnMeasure" (From Android Documentary: OnMeasure - Called to determine the size requirements for this view and all of its children). So every time the view was changed and has to be drawn again or when the device rotates, this event will be called. This is the moment where we have to calculate the size of our surfaceView. Therefore we need to know the orientation of the device.
To be able to handle the orientation-changed-event we have to set a flag in the AndroidManifest class.
So for the activity, which will contain the mediaplayer, we have to set android:configChanges="screenSize|orientation". Now we can handle this event without a restart of our activity and pass the new orientation to our surfaceview.
@Override
public void onConfigurationChanged(Configuration _newConfig) {
if (mSurfaceView != null)
mSurfaceView.setConfiguration(_newConfig);
super.onConfigurationChanged(_newConfig);
}
Now our surfaceview is able to change the size depending on the orientation. To add it to our activity-layout we can add it to the xml as followed:
LinearLayout ...
package-name.AutoResizeSurfaceView
android:id="@+id/mediaplayer_surfaceview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" /
...
/LinearLayout
So actually that's it. A possible implementation of the custom surfaceview is attached to this solution. The final step is to implement the mediaplayer, which uses our custom surfaceview.
The implementation of the mediaplayer is documented here:
http://developer.android.com/guide/topics/media/mediaplayer.html
And a really good example-project can be found in the platforms-examples which are part of the Android SDK.