android-如何使用ACTION_VIDEO_CAPTURE动作将意图的文件输出设置为mp4?

android-如何使用ACTION_VIDEO_CAPTURE动作将意图的文件输出设置为mp4?,第1张

概述当我使用本机应用相机拍摄视频时,输出文件的扩展名为3gp.我需要使用ACTION_VIDEO_CAPTURE意向动作意图摄像头,这将产生一个具有mp4文件扩展名的文件.我该怎么做?解决方法:您可以继续尝试使用dis代码:intent=newIntent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);

当我使用本机应用相机拍摄视频时,输出文件的扩展名为3gp.我需要使用ACTION_VIDEO_CAPTURE意向动作来意图摄像头,这将产生一个具有mp4文件扩展名的文件.我该怎么做?

解决方法:

您可以继续尝试使用dis代码:

intent = new Intent(androID.provIDer.MediaStore.ACTION_VIDEO_CAPTURE);       fileUri = getoutputMediafile(MEDIA_TYPE_VIDEO);  // create a file to save the vIDeo in specific folder (this works for vIDeo only)    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);    intent.putExtra(MediaStore.EXTRA_VIDEO_QUAliTY, 1); // set the vIDeo image quality to high    // start the VIDeo Capture Intent    startActivityForResult(intent, REQUEST_VIDEO_CAPTURED_NEXUS);

捕获完成后将调用此方法

protected voID onActivityResult(int requestCode, int resultCode, Intent data) {        if (resultCode == Activity.RESulT_OK) {            switch (requestCode) {    case REQUEST_VIDEO_CAPTURED_NEXUS:    this.vIDeoFromCamera(resultCode, data);    break;default:                break;            }        }    }

私有无效vIDeoFromCamera(int resultCode,Intent data){

    if(fileUri != null) {        Log.d(TAG, "VIDeo saved to:\n" + fileUri);        Log.d(TAG, "VIDeo path:\n" + fileUri.getPath());        Log.d(TAG, "VIDeo name:\n" + getname(fileUri)); // use uri.getLastPathSegment() if store in folder//use the file Uri.    }}

使用以下方法获取输出媒体文件uri

public Uri getoutputMediafile(int type)    {        // To be safe, you should check that the SDCard is mounted        if(Environment.getExternalStorageState() != null) {            // this works for AndroID 2.2 and above            file mediaStorageDir = new file(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), "SMW_VIDEO");            // This location works best if you want the created images to be shared            // between applications and persist after your app has been uninstalled.            // Create the storage directory if it does not exist            if (! mediaStorageDir.exists()) {                if (! mediaStorageDir.mkdirs()) {                    Log.d(TAG, "Failed to create directory");                    return null;                }            }            // Create a media file name            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());            file mediafile;           if(type == MEDIA_TYPE_VIDEO) {                mediafile = new file(mediaStorageDir.getPath() + file.separator +                "VID_"+ timeStamp + ".mp4");            } else {                return null;            }            return Uri.fromfile(mediafile);        }        return null;    }

这会将捕获的视频保存为纯MP4格式.

总结

以上是内存溢出为你收集整理的android-如何使用ACTION_VIDEO_CAPTURE动作将意图的文件输出设置为mp4?全部内容,希望文章能够帮你解决android-如何使用ACTION_VIDEO_CAPTURE动作将意图的文件输出设置为mp4?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1094768.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存