public class MainActivity extends Activity implements OnClickListener{
private Button play,pause,stop;
private VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView=(VideoView) findViewById(R.id.vv);
play=(Button) findViewById(R.id.play);
pause=(Button) findViewById(R.id.pause);
stop=(Button) findViewById(R.id.stop);
play.setOnClickListener(this);
pause.setOnClickListener(this);
stop.setOnClickListener(this);
initVideoPath();
}
private void initVideoPath(){
File file=new File(Environment.getExternalStorageDirectory(),"zxc.3gp");
videoView.setVideoPath(file.getPath());
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.play:
if (!videoView.isPlaying()) {
videoView.start();
}
break;
case R.id.pause:
if (videoView.isPlaying()) {
videoView.pause();
}
break;
case R.id.stop:
if (videoView.isPlaying()) {
videoView.resume();
}
break;
default:
break;
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (videoView!=null) {
videoView.suspend();
}
}
}
支持3gp,mp4格式
不堪大用