标签:
package com.example.meidiaplayar;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends Activity {
private VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = (VideoView) findViewById(R.id.video);
//String path=Environment.getExternalStorageDirectory().getPath();
//设置视频路径
videoView.setVideoPath("/mnt/sdcard/xiaopohai.3gp");
//设置控制器
MediaController controller=new MediaController(MainActivity.this);
videoView.setMediaController(controller);
controller.setMediaPlayer(videoView);
videoView.start();
//将保存的数据给VideoView
if(savedInstanceState!=null){
int time = savedInstanceState.getInt("time");
videoView.seekTo(time);
}
}
//切换屏幕时,走以下代码;
@Override
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
outState.putInt("time", videoView.getCurrentPosition());
super.onSaveInstanceState(outState);
}
}
横竖屏切换播放短视频(前提是手机需要先按下横竖屏切换的按钮)
标签:
原文地址:http://www.cnblogs.com/zhengyanyan/p/5392726.html