Android : Android switch VideoView orientation from Portrait to Landscape without stretching the video horizontally

on Monday, October 27, 2014


I have an application that play video from the external storage. The videos look fine in portrait mode, but they are stretched in landscape mode. Is there any easy way to set the landscape mode video playback width to fit the video ?


this is my video playing activity:



public class PlayVideoActivity extends Activity implements OnCompletionListener {

private VideoView video;
private MediaController controller;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_play_video);
video = (VideoView) findViewById(R.id.vwPlayVideo);
controller = new MediaController(this);

video.setOnCompletionListener(this);


Bundle extras = getIntent().getExtras();
if(extras != null){
String videoPath = extras.getString("videoPath");
video.setVideoPath(videoPath);
controller.setMediaPlayer(video);
video.setMediaController(controller);
video.requestFocus();
video.start();

if(savedInstanceState != null){
video.seekTo(savedInstanceState.getInt("currentPos"));
}
}
}

@Override
public void onCompletion(MediaPlayer mp) {
finish();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
if(video.isPlaying()){
outState.putInt("currentPos", video.getCurrentPosition());
}
super.onSaveInstanceState(outState);
}

}

0 comments:

Post a Comment