Cordova选择视频结果路径而不扩展

Cordova choose video resulting path without extension

本文关键字:扩展 路径 结果 选择 视频 Cordova      更新时间:2023-09-26

我使用下面的代码从库中选择视频

navigator.camera.getPicture(function (data) {
    callback(true, data);
},
function (e) {
    callback(false, null);
}, {
    destinationType: navigator.camera.DestinationType.FILE_URI,
    sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
    mediaType: navigator.camera.MediaType.VIDEO
});

但是在回调中,我得到了以下格式的路径

 content://media/external/video/media/832

如何获取原始文件路径?

我知道这有点晚了,但也许其他人需要这个(使用resolveLocalFileSystemURL然后使用toURL())检查此代码

            navigator.camera.getPicture(onSuccess, onFail, {
                limit: 1,
                mediaType: window.Camera.MediaType.VIDEO,
                destinationType: window.Camera.DestinationType.FILE_URI,
                sourceType: Camera.PictureSourceType.PHOTOLIBRARY
            });
            function onSuccess(fileURI) {
                window.resolveLocalFileSystemURL(fileURI,
   function (fileEntry) {
       console.log(fileEntry.toURL());
       //console.log(fileEntry.fullPath);
   },
   function () { });
            }
            function onFail(error) {
                console.log(error);
            }

step1添加Cordova -filepath-resolver

对于Ionic,你也可以使用:

ionic plugin add cordova-filepath-resolver

步骤2

把代码放到

 function camerasucess(videourl) {
            //videourl is something like this    content //media/external/video
            var successCallback = function (data) {
                console.log(JSON.stringify(data));
                //here you will get the correct path of the video file and you can upload the video file
                $scope.data = data;
            };
            var errorCallback = function (data) {
                console.log(JSON.stringify(data));
            };

            window.FilePath.resolveNativePath(videourl, successCallback, errorCallback);

        };
        function cameraError(data) {
            alert(JSON.stringify(data));
        };
        if (navigator.camera)
        {
            navigator.camera.getPicture(camerasucess, cameraError, {
                sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY, mediaType: navigator.camera.MediaType.VIDEO,
            });
        }