android调用本地录制程序获取录制文件路径的问题(摘)

来源:未知 责任编辑:责任编辑 发表时间:2014-04-20 03:36 点击:

I use the MediaStore.ACTION_VIDEO_CAPTURE intent class to capture the video, the video stored in default location(gallery),i want to store the video in specific location with specific name.
I use MediaStore.EXTRA_MEDIA_TITLE and MediaStore.EXTRA_MEDIA_OUTPUT but I don`t get the video at correct location, at least I need the path of recorded video.
 方案一:
Trick is to insert media into database before recording:
String fileName = "captureTemp.mp4";  
ContentValues values = new ContentValues();  
values.put(MediaStore.Video.Media.TITLE, fileName);  
cameraVideoURI = getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);  
 
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);  
intent.putExtra(MediaStore.EXTRA_OUTPUT, cameraVideoURI);  
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, MAXIMUM_VIDEO_SIZE);               
startActivityForResult(intent, CAPTURE_VIDEO_INTENT);
and then onActivityResult() use saved cameraVideoUri to reference recorded video:
       String[] projection = { MediaStore.Video.Media.DATA, MediaStore.Video.Media.SIZE  }; 
       Cursor cursor = managedQuery(cameraVideoURI, projection, null, null, null); 
       int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); 
       int column_index_size = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE); 
       cursor.moveToFirst(); 
       String recordedVideoFilePath = cursor.getString(column_index_data);
       int recordedVideoFileSize = cursor.getInt(column_index_size);
方案二:
The solution from Zelimir doesn't work in my case (the videos were at the right location but had a size of zero bytes). So i've found another solution:
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
  super.onActivityResult(requestCode, resultCode, intent);
 
  if (resultCode != RESULT_OK) return;
 
  try {
    AssetFileDescriptor videoAsset = getContentResolver().openAssetFileDescriptor(intent.getData(), "r");
    FileInputStream fis = videoAsset.createInputStream();
    File tmpFile = new File(Environment.getExternalStorageDirectory(),"VideoFile.3gp"); 
    FileOutputStream fos = new FileOutputStream(tmpFile);
 
    byte[] buf = new byte[1024];
    int len;

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • Android 完全退出程序
  • 原创:Android应用开发-Andorid歌词秀,含源码
  • android 屏幕保护
  • Android手机软件汉化教程---第四课 dex文件汉化
  • 众多Android 开源项目推荐,给力工作给力学习
  • Android Audio代码分析4
  • Android得到已安装的应用程序信息!
  • Android开发者指南(29) —— USB Host and Accessory
  • Android成长的幕后推手:工程师鲁宾
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1