调用系统相机开启录像功能
来源:互联网 发布:齐天乐春节晚会 知乎 编辑:程序博客网 时间:2024/06/06 02:02
在清单文件中加入相应的权限
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
在布局中activity_camera_vodeo
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_camera_vodeo"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/but_camera"
android:text="开始拍摄"
android:onClick="camera"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:id="@+id/my_iv"
android:src="@mipmap/ic_launcher"
android:layout_below="@id/but_camera"/>
<VideoView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/my_vv"
android:layout_below="@id/my_iv"/>
</RelativeLayout>
在主页面中
package alice.bw.com.day04systemcamera.demo01;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.VideoView;
import alice.bw.com.day04systemcamera.R;
/**
* 使用照相机的录像功能
*/
public class CameraVodeoActivity extends AppCompatActivity {
private VideoView mVv;
//第二部分
private ImageView mIv;
//使用照相机需要添加权限, 动态给权限, 读取sd卡的权限
//6.0后需要动态的设置权限, 所有我们把目标版本给为22就可以了
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera_vodeo);
mVv = (VideoView) findViewById(R.id.my_vv);
mIv = (ImageView) findViewById(R.id.my_iv);
}
public void camera(View view) {
//跳转到摄像头的界面
Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);//录像
startActivityForResult(intent,100);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==100 && resultCode == RESULT_OK) {
Log.e("sxl","拍摄完毕");
//得到图片资源的地址
Uri uri = data.getData();
//从本地的uri地址中获取内容
// 本地的Uri地址, 获取本地的数据, 可以通过ContentProvider获取
Cursor cursor = getContentResolver().query(uri,null,null,null,null);
if (cursor.moveToFirst()) {
//获取第一条数据的地址
String path = cursor.getString(cursor.getColumnIndex("_data"));
Log.d("sxl", "onActivityResult: "+path);
//设置播放的地址
mVv.setVideoURI(Uri.parse(path));
//添加媒体控制器 -------- 可以放一放在说
mVv.setMediaController(new MediaController(this));
//开始播放视频
mVv.start();
//制作视频的缩略图
// ['θʌmnel]
//路径 , kind常量值 从视频中提取缩略图
Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(path,MediaStore.Video.Thumbnails.MINI_KIND);
//为ImagView 设置从视频中提取到的缩略图
mIv.setImageBitmap(bitmap);
}
}
}
}
- 调用系统相机开启录像功能
- android -调用系统相机录像
- 安卓自定义相机录像功能全解(不调用系统相机)
- Android 调用系统相机拍照、录像
- 调用系统相机拍照功能
- 调用系统相机拍照、调用相册、调用系统录像并获取缩略图
- 使用系统相机实现录像
- Atititjs h5调用摄像头视频聊天 拍照功能 相机功能 录像attilax总结
- Android调用系统相机拍照,从图库中选择照片,调用系统摄像机录像
- android调用系统相机实现拍照功能
- android调用系统相机实现拍照功能
- android调用系统相机实现拍照功能
- android调用系统相机实现拍照功能
- android调用系统相机实现拍照功能
- android调用系统相机实现拍照功能
- iOS[系统功能篇]之调用相机
- android 调用系统相机、相册剪切功能
- 调用系统拍照、录像、录音功能并播放的demo
- linux 修改主机名
- 171021 c++中++i与i++的区别
- mysql 存储引擎总结
- UVA11557 KMP+HASH
- Java实现身份证号码验证
- 调用系统相机开启录像功能
- 安卓相机的使用
- 多个.c文件编译
- C++ 直接初始化和拷贝初始化
- 选择分支语句,continue与break和return之间的区别,随机数,清除屏幕垃圾,退出程序
- 前端之nodejs(三)
- 什么是mata标签
- SSH党校培训系统
- 我的周内反思