FileReader not reading recorded video file in Ionic

71 Views Asked by At

I want to get base64 from video file obtained from Cordova Media Capture's captureVideo() method. I am able to get File using resolveLocalFilesystemUrl() method but when I try to read that File using FileReader, there is no callback event, nor do I get any error. I found from this link that file obtained from Media Capture has issue in reading. I tried reading the File using File plugin's readAsDataURL() method but without success. I also tried to create AN objectURL using URL.createObjectURL(file) method but getting error. Is there any other way to get base64 or thumbnail?

convertMediaFileToBlob(path: string){
    this.file.resolveLocalFilesystemUrl(path)
    .then((fileEntry:any) => {
        fileEntry.file((file:any)=>{

          let reader = new FileReader();
          reader.onloadend = () => {
            console.log('onloadend: ',reader.result)
            
          };
          reader.onerror = (error) => {
            console.log('onerror error: ',error)
          };
          reader.onabort = () => {
            console.log('onabort')
          };
          reader.readAsDataURL(myfile);
         
        })
    })
    .catch((e:any) => {
      console.log('err: ',e)
    });
  }
async recordVideo(){
    let options: CaptureVideoOptions = { limit: 1 }
    this.mediaCapture.captureVideo(options)
      .then(
        (data: any) => {
          const path = data[0]?.fullPath
          this.convertMediaFileToBlob(path)
        },
        (err: CaptureError) => console.error(err)
      );
}

0

There are 0 best solutions below