【问题标题】:PhoneGap/Cordova - Is it possible to create a new album in the device media library?PhoneGap/Cordova - 是否可以在设备媒体库中创建新专辑?
【发布时间】:2013-10-15 06:20:41
【问题描述】:

使用PhoneGap (3.0.0) 相机插件,可以捕捉新视频或从相机胶卷或相册中选择一个 但是是否可以通过 API 创建新专辑?

在我们的移动应用项目中,在初始化阶段,我们想要检查“swingAlbum”是否存在,如果不存在则直接创建它。然后,用户将能够使用标准设备摄像头捕获功能将剪辑存储到此“swingAlbum”中,以供以后与我们的应用程序一起使用。

【问题讨论】:

  • 你需要为此创建插件

标签: android ios cordova camera


【解决方案1】:

试试这个:

   <button onclick="capture()"></button>





    function capture() {
        navigator.camera.getPicture(getImageURI, function (message) {
            alert('Image Capture Failed');
        }, {
            quality: 100,
            destinationType: Camera.DestinationType.FILE_URI,
            correctOrientation: true
        });


    }


    function getImageURI(imageURI) {
        var gotFileEntry = function (fileEntry) {
//        alert("got image file entry: " + fileEntry.fullPath);
            var gotFileSystem = function (fileSystem) {
                fileSystem.root.getDirectory('swingAlbum', {
                    create: true
                }, function (dataDir) {
                    fileName = "myfile.jpg";
                    fileEntry.moveTo(dataDir, fileName, success, fsFail);
                }, dirFail);

            };
            // get file system to copy or move image file to
            window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem, fsFail);
        };
        // resolve file system for image
        window.resolveLocalFileSystemURI(imageURI, gotFileEntry, fsFail);

        // file system fail
        var fsFail = function (error) {
            alert("failed with error code: " + error.code);

        };

        var dirFail = function (error) {
            alert("Directory error code: " + error.code);

        };
    }

【讨论】:

  • 谢谢,所以在这种情况下,swingAlbum 是在添加第一个媒体时创建的,但我想我们可以在应用首次初始化期间添加媒体来创建它
  • 是的,当然你可以,但是在运行时创建它是安全的..因为假设如果有人删除了目录会发生什么?
猜你喜欢
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-01
  • 2012-12-29
  • 1970-01-01
  • 1970-01-01
  • 2022-01-19
相关资源
最近更新 更多