1
我有一个应用程序可以播放来自外部存储器的视频。这些视频在纵向模式下看起来很好,但它们在横向模式下延伸。是否有任何简单的方法来设置横向模式视频播放宽度以适应视频?Android切换VideoView方向从纵向到横向而不横向拉伸视频
这是我的视频播放活动:
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);
}
}
编辑:activity_play_video.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<VideoView
android:id="@+id/vwPlayVideo"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
向我们显示您的xml请求! – 2014-10-27 15:17:42
检查我更新的答案@ wutk3ks – Marcus 2014-10-27 15:19:26
尝试wrap_content的宽度和高度的VideoView。 – 2014-10-27 15:22:00