如何将录制的视频保存到phonegap中的指定文件

Posted

技术标签:

【中文标题】如何将录制的视频保存到phonegap中的指定文件【英文标题】:How to save a recorded video to a specified file in phonegap 【发布时间】:2013-06-12 11:01:03 【问题描述】:

您好,我正在尝试创建一个 phonegap 应用程序,您可以在其中将录制的视频保存到文件夹而不是图库中,有什么想法吗?我查看了 File_URI,但不知道怎么做?!我想只在 capture.js 文件中执行此操作(创建新功能并采取预防措施,因此每次拍照时都不会创建相同的文件)但是,它不会将它们保存到画廊和我指定的文件夹中吗? ???

【问题讨论】:

【参考方案1】:

我用图像这样解决了这个问题:

首先使用 FILE_URI 的目标类型设置拍照选项

var destinationType = navigator.camera.DestinationType;

            navigator.camera.getPicture(this.onPhotoDataSuccess, this.onFailTakingPicture,
                
                    quality: 80,
                    destinationType: destinationType.FILE_URI,
                    encodingType: Camera.EncodingType.JPEG,
                    targetWidth: 250,
                    targetHeight: 250,
                );

拍摄照片时,使用 imageURI 调用 onPhotoDataSucces。然后请求phonegap的文件系统。

onPhotoDataSuccess : function(imageURI) 

                window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, this.gotFileSystem, this.failFileSystem);

            ,

当你得到 fileSystemEntry 然后在 SD 的根目录下创建一个目录

 gotFileSystem: function(fileSystem) 
            fileSystem.root.getDirectory("voetstappen_opdrachten", create: true, exclusive: false, this.gotDirEntry, this.failFileSystem)
        ,

在回调函数this.gotDirEntry() 中,您获得了目录对象(dirEntry),您可以使用它来设置对象的属性,以便以后使用它来保存文件

  gotDirEntry: function (dirEntry) 
                    //set a object's propery with the dirEntry
                    this.dirEntry = dirEntry
                    // use the resolveLocalFileSystemUri to save the captured image to a file
                    window.resolveLocalFileSystemURI(this.imageURI, this.gotFileEntry, this.failFileSystem);
                ,

最后你得到了 fileEntry,然后像这样将它移动到目录中:

           gotFileEntry: function(fileEntry) 
  fileEntry.moveTo(this.dirEntry, "objective" + "name" + ".jpg", function(fileEntry) //callback  

【讨论】:

非常感谢您的意见,您让我走上了正轨。我决定这样做。 首先是一个检查文件的函数 function checkIfFileExists(fileExists) window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) fileSystem.root.getFile(path, create: false , 文件已存在); ); function fileExists(fileEntry) return true; 很抱歉我在这里写代码的努力很糟糕......我会优雅地放弃谢谢@Sjaak

以上是关于如何将录制的视频保存到phonegap中的指定文件的主要内容,如果未能解决你的问题,请参考以下文章

phoneGap/Apache Cordova 媒体捕获插件 - 多视频录制

如何将 UIImage 保存到文档目录?

如何将我的视频保存到相册中的特殊文件夹?

在服务器端录制语音视频

以 mp4 格式录制、保存和/或转换视频?

如何把直播保存到阿里云?