使用离子3本机相机插件选择视频 [英] pick video using ionic 3 native camera plugin

查看:124
本文介绍了使用离子3本机相机插件选择视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

this.camera.getPicture({
      quality: 50,
      destinationType: this.camera.DestinationType.DATA_URL,
      mediaType: this.camera.MediaType.VIDEO,
      sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
    }).then((videoData) => {

    console.log('video data', videoData);

我无法将视频数据发送到服务器。

I can't send the video data to server.

我在这里遇到的第一件事就是destinationType如何影响返回的结果,因为无论我设置什么(DATA_URL或File_Uri)它总是返回一些这个结构的url /storage/emulated/0/DCIM/Camera/VID_20180312_210545.mp4 。(仅供参考:我目前正在Android平台上进行测试)。我可以通过简单的方式预览视频将它放在视频src中,但我无法将此视频发送到服务器。

The very first thing I'm struggling with here is that how is destinationType affecting the returned result because no matter what I set (either DATA_URL or File_Uri) it always returns me some url of this structure /storage/emulated/0/DCIM/Camera/VID_20180312_210545.mp4 . (FYI: I am currently testing this on android platform). I am able to preview the video by simply putting it in video src but I am unable to send this video to the server.

这是我用来从返回的<$获取视频文件的方法C $ C> /存储喜欢URL,然后将视频发送到服务器。

This is the approach that I am using to get the video file from the returned /storage like URL and then to send the video to server.

return this.file.resolveLocalFilesystemUrl(data).then((entry:FileEntry)=>{
      debugger;
      return new Promise((resolve, reject)=>{
        entry.file((file)=>{
          let fileReader = new FileReader();
          fileReader.onloadend = ()=>{
            let blob = new Blob([fileReader.result], {type:file.type});
            resolve({blob: blob, file: file});
          };
          fileReader.readAsArrayBuffer(file);
        })
      })
    })

其中传递给resolveLocalFilesystemUrl的数据参数是我之前提到的相同url(/ storage / 0 ..)。

Where data parameter being passed to the resolveLocalFilesystemUrl is that same url (/storage/0..) that I mentioned earlier.

但这会引发错误,错误代码为5&错误消息ENCODING_ERR

But this throws an error with error code 5 & error message ENCODING_ERR

我没有故意将此处的编码类型传递给图像文件。

I am not passing the encoding type here on purpose as that is for image files.

重要提示:如果我将'file://'添加到数据中,然后将其传递给 resolveLocalFilesystemUrl(),就像这样 this.file.resolveLocalFilesystemUrl('file://'+ data).then(())然后我能够创建我发送到服务器并且服务器已成功保存的文件条目视频。但我想使用更多的跨平台方法,这种方法适用于Android和Android。 iOS

Important Note: if I add 'file://' to the data and then pass it to resolveLocalFilesystemUrl() like this this.file.resolveLocalFilesystemUrl('file://'+data).then(()) then I am able to create file entry which I've sent to the server and server has successfully saved the video. But I wanted to use more of a cross platform approach that will work both on Android & iOS

推荐答案

使用Android,您需要更正您的网址。

Working with Android you need to correct your URL.

当您从库中选择视频时,您应该使用resolveNativePath。

You should use the resolveNativePath when you choose a video from the library.

您可以在此处找到更多文档:

More docs you can find here:

https://ionicframework.com/docs/native/file-path/

这篇关于使用离子3本机相机插件选择视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆