播放视频

来源:互联网 发布:胸痛中心数据填报 编辑:程序博客网 时间:2024/05/02 05:04
public class MainActivity extends Activity implements OnClickListener{private Button play,pause,stop;private VideoView videoView;@Overrideprotected 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());}@Overridepublic 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;}}@Overrideprotected void onDestroy() {super.onDestroy();if (videoView!=null) {videoView.suspend();}}}

支持3gp,mp4格式

不堪大用

0 0
原创粉丝点击