android VideoView播放视频,MediaRecorder 录音
来源:学习笔记 责任编辑:栏目编辑 发表时间:2013-07-01 07:53 点击:次
1. 在Android系统中,是通过MediaPalyer类播放媒体文件的(包括视频和音频)。虽然这个类已经比较简单了,但是还需要控制各种状态,对于视频还需要设置输出窗口,还是需要仔细研究的。为了避免这些麻烦事儿,Android框架提供了VideoView类来封装MediaPalyer
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- //全屏
- this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
- //标题去掉
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
- //要在全屏等设置完毕后再加载布局
- setContentView(R.layout.main);
- //定义UI组件
- VideoView videoView = (VideoView) findViewById(R.id.VideoView01);
- //定义MediaController对象
- MediaController mediaController = new MediaController(this);
- //设置VideoView的控制器是mediaController
- videoView.setMediaController(mediaController);
- //这两种方法都可以 videoView.setVideoPath("file:///sdcard/love_480320.mp4");
- videoView.setVideoURI(Uri.parse("/sdcard/love_480320.mp4"));
- //启动后就播放
- videoView.start();
- }
2. MediaRecorder
A common case of using MediaRecorder to record audio works as follows:
- MediaRecorder recorder = new MediaRecorder();
- recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
- recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
- recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
- recorder.setOutputFile(PATH_NAME);
- recorder.prepare();
- recorder.start(); // Recording is now started&n
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>