我如何从我的库中加载视频文件?离子3

问题描述 投票:1回答:1

我观察到Ionic View不再支持原生文件see list here

我试图通过使用Native Camera来访问视频,从我的库中获取视频。它可以为我的视频返回3种不同格式的路径(DATA_URL,FILE_URI和NATIVE_URI).reference to Native Camera here

我目前正在使用this post推荐的FILE_URI。它返回类似“/storage/emulated/0/DCIM/Camera/VID_20180312_210545.mp4”的内容

请看下面的代码。为了更好地理解,使用“// ** comment ***”的评论突出显示当前行为:

addVideoToOffer(){        
    this.platform.ready().then(() =>{
        const options: CameraOptions = {
          sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
          destinationType: this.camera.DestinationType.FILE_URI,
          mediaType: this.camera.MediaType.VIDEO,
        }
        this.camera.getPicture(options).then((data_uri) => {       
          this.readVideoFileasGeneral(data_uri);
       });
    });

  }

  readVideoFileasGeneral(data_uri) {  
      if(!data_uri.includes('file://')) {
        data_uri = 'file://' + data_uri;  
      }             
      return this.file.resolveLocalFilesystemUrl(data_uri)
            .then((entry: FileEntry) => {
            //***it does not get in here***
            this.presentQuickToastMessage(data_uri); 
            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); 
                              });  
                        })
            })
            .catch((error) => { 
              this.presentQuickToastMessage(error); 
              //***it presents "plugin_not_installed" here***
            });
  }

我知道我收到此消息,因为不再支持本机文件(可能是plugin_not_installed消息的原因)。但是,我仍然需要完成这项任务。所以,如果有人知道我可以使用什么来将选定的视频放在blob中,那就太好了!

感谢读到这里,干杯,Roger A L.

ionic-framework ionic3 ionic-native ionic-view
1个回答
0
投票
 makeFileIntoBlob(uri) {
    // get the correct path for resolve device file system
    let pathIndex = uri.indexOf('var');
    let correctPath = uri.slice(+pathIndex);

    this.file
        .resolveLocalFilesystemUrl((this.platform.is('ios') ? 'file:///' : '') + correctPath)
        .then(entry => (<FileEntry>entry).file(file => this.readFile(file)))
        .catch(err => console.log('ERROR: ', err));
}

readFile(file) {
    if(file) {
        const reader = new FileReader();
        reader.onloadend = () => {
            const blob: any  = new Blob([reader.result], { type: file.type });
            blob.name = file.name;
            console.log(blob);

            return blob;
        };
        reader.readAsArrayBuffer(file);
    }
}

你需要摆脱/ private /并保留file:///,这样你的路径就像file:/// var /

© www.soinside.com 2019 - 2024. All rights reserved.