无法使用Cordova从设备上传视频

时间:2019-11-03 05:51:13

标签: javascript cordova cordova-plugins quasar-framework quasar

我无法从用户库中选择视频并上传。不过,我可以选择照片,拍照/录像以及通过使用浏览器并转到/ downloads(从野生动物园下载)来上传视频

这在iOS模拟器和我的iPhone 5上运行良好,但在我的iPhone 7或11上却无法运行。

    selectMediaType(type){
      alert(cordova.file.applicationStorageDirectory)
    try{
      if(type == 0){ //image


        navigator.camera.getPicture(
          data => {
            // on success
            var img = `data:image/jpeg;base64,${data}`;
            this.imageSrc.push(img);

          },
          () => {
            // on fail
            this.$q.notify("Could not access device camera.");
          },
          {
            sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
            destinationType: navigator.camera.DestinationType.DATA_URL,      
            quality: 100,
            targetWidth: 1000,
            targetHeight: 1000,
            encodingType: navigator.camera.EncodingType.JPEG,      
            correctOrientation: true
          }
        );

      }else if(type == 1 ){ //video
        navigator.camera.getPicture(
         async data => {
            // on success
       //     var img = `data:image/jpeg;base64,${data}`;
       //     this.imageSrc.push(img);

              if(this.$q.platform.is.ios){
                  this.getBase64StringByFilePath( data)
              }else{
                  this.getBase64StringByFilePath('file://'+ data)     //android
              }
          },
          () => {
            // on fail
            this.$q.notify("Could not access device camera.");
          },
          {
            sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
            destinationType: navigator.camera.DestinationType.FILE_URI,      
      //      quality: 100,
       //     targetWidth: 1000,
      //      targetHeight: 1000,
      //      encodingType: this.camera.EncodingType.JPEG,      
            mediaType: navigator.camera.MediaType.VIDEO,
            correctOrientation: true
          }
         );
      }
       }catch(err){
        alert(2222) 
    }
    },
    getBase64StringByFilePath(fileURL) {

     alert(fileURL)
     var that = this;
      try{
          window.resolveLocalFileSystemURL(fileURL, function(fileEntry) {

            return fileEntry.file(function(data) {
              alert(data)
              var reader = new FileReader();
              reader.onload = function(e) {
                alert(e.target.result)
                var v = "<video style='height:240px;'  controls>";
                v +=
                  "<source src='" + e.target.result + "' type='video/mp4'>";
                v += "</video>";

                document.querySelector("#videoArea").innerHTML = v;
                that.loadingMedia = false
              };
              reader.onerror = error=>{
                that.loadingMedia = false

              }
              that.loadingMedia = true
              return reader.readAsDataURL(data);

            });
          });
      }catch(err)
         alet(err)
      }
    },

当我选择视频并警告路径时,它似乎显示了正确的路径。我的应用程序上有一个“预览”位置,该位置应该可以显示视频,但是除非使用iPhone 5或iOS模拟器,否则它永远不会显示

0 个答案:

没有答案