录像机应用
** * 录像 */ public void video(View v){ //创建意图对象 Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); //设置录像的存储位置 File file = new File("/mnt/sdcard/luxing.mp4"); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); // set the image file name //设置录像质量 intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high // start the Video Capture Intent startActivityForResult(intent, 2); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (data == null) { return; } switch (requestCode) { case 1: Toast.makeText(this, "拍照成功 /mnt/sdcard/zanmen.jpg", 0).show(); break; case 2: Toast.makeText(this, "录像成功 /mnt/sdcard/luxiang.mp4", 0).show(); break; default: break; } }
添加权限: <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
最后,关注【码上加油站】微信公众号后,有疑惑有问题想加油的小伙伴可以码上加入社群,让我们一起码上加油吧!!!