【Android开发小记--15】录制视频
来源:互联网 发布:java基础知识txt下载 编辑:程序博客网 时间:2024/04/30 15:38
通过Intent 调用系统录制视频功能
使用VideoView 播放录制的视频
使用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"/>
具体代码点击
0 0
- 【Android开发小记--15】录制视频
- Android小记:Camara录制视频的调用
- Android开发之视频录制
- Android开发之录制视频
- Android开发短视频录制
- 【Android开发小记--13】录制音频
- Android开发之使用MediaRecorder录制视频
- Android开发之使用MediaRecorder录制视频
- Android开发之视频录制与播放
- IOS开发---视频录制
- android视频录制(调用系统视频录制)
- Android 视频录制
- android视频录制
- android 音视频录制
- android视频录制例子
- Android录制视频(五)
- Android录制视频(四)
- Android录制视频(三)
- 动态规划 DP 2
- 吃糖果
- Qt5.5 使用Git+VS2010静态编译
- apache commons io 2.2(三)Monitor部分
- 3-4
- 【Android开发小记--15】录制视频
- find()和filter()函数的用法区别
- 大数据 IMF传奇行动 如何 搭建 8台设备的 hadoop分布式集群
- 华为手机 logcat不输入错误日志
- [1651] Red packet【二分】
- uva 1625 color length
- HDU 1007 (分治递归)
- NYOJ 题目58 最小步数
- Linux命令行学习之路(七)——定时执行