【Android开发小记--15】录制视频
2016-02-07 14:39
435 查看
通过Intent 调用系统录制视频功能
使用VideoView 播放录制的视频
首先,设置布局文件,添加 button 和 videoView :
接着,在 MainActivity.java 中
通过Intent 调用系统录制视频功能;使用VideoView 播放录制的视频
1. 使用系统的 Uri 路径存储
2.使用自定义的 Uri 路径存储
注意添加读取外部文件权限:
具体代码点击
使用VideoView 播放录制的视频
首先,设置布局文件,添加 button 和 videoView :
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.dingding.recordervideo.MainActivity"> <Button android:id="@+id/btn_recorder" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="调用系统录制视频功能" /> <Button android:id="@+id/btn_play" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="播放视频"/> <VideoView android:id="@+id/videoView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"/> </LinearLayout>
接着,在 MainActivity.java 中
通过Intent 调用系统录制视频功能;使用VideoView 播放录制的视频
1. 使用系统的 Uri 路径存储
2.使用自定义的 Uri 路径存储
public class MainActivity extends AppCompatActivity implements View.OnClickListener { private Button btn_recorder; private Button btn_play; private VideoView videoView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn_recorder = (Button) findViewById(R.id.btn_recorder); btn_play = (Button) findViewById(R.id.btn_play); videoView = (VideoView) findViewById(R.id.videoView); btn_recorder.setOnClickListener(this); btn_play.setOnClickListener(this); } private final int VIDEO_RECORDER = 1; private Uri outputUri; @Override public void onClick(View v) { switch (v.getId()){ case R.id.btn_recorder: //------------------ 1 ---------------------------------------------- // //调用系统录制视频程序 // Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); // startActivityForResult(intent,VIDEO_RECORDER); //------------------ 2 ---------------------------------------------- //自定义录制的路径 File file = new File(Environment.getExternalStorageDirectory(),"myRecorder.mp4"); outputUri = Uri.fromFile(file); //调用系统录制视频程序 Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT,outputUri); startActivityForResult(intent, VIDEO_RECORDER); break; case R.id.btn_play: videoView.setVideoURI(outputUri); videoView.start(); break; } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode==RESULT_OK){ //------------------ 1 ---------------------------------------------- // outputUri = data.getData();//获取到录制视频后的uri } } }
注意添加读取外部文件权限:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
具体代码点击
相关文章推荐
- android:qq的欢迎界面
- 【Android开发小记--14】简单拍照功能的实现
- android studio 快捷键--持续更新
- Android 俄罗斯方块开发(附源码)
- 【Android开发小记--13】录制音频
- android wifi调试程序问题
- Styling Views on Android
- Android随性笔录之活动返回信息
- 【Android开发小记--12】同步歌词
- android逆向的一些工具
- ANDROID_MARS学习笔记_S01_003layout初步
- 让 Android 手机也具备 Continuum 功能:连接大屏就能当 PC 用
- 【Android】5.8 滑动条(SeekBar)
- 【Android】5.7 图片库(Galery)
- 【Android】5.6 弹出菜单(PopUp Menus)
- 【Android】5.5 状态切换(Switch)和评级条(RatingBar)
- 【Android】5.4 下拉框(Spinner)
- 【Android】5.3 单选和复选
- 【Android】5.2 图像按钮和图片格式
- 【Android】5.1 按钮和文本框