首页 > 解决方案 > 在ionic的相机预览插件的stopRecordVideo()函数返回的文件路径上找不到视频

问题描述

当我stopRecordVideo()在 ionic 中调用相机预览插件时,在返回的文件路径上查找录制的视频文件时遇到问题。

我使用的功能:
开始录制

startRecording(){
 options = {
   cameraDirection: this.cameraPreview.CAMERA_DIRECTION.BACK,
   width: (window.screen.width / 2),
   height: (window.screen.height / 2),
   quality: 60,
   withFlash: false,
   storeToFile: true,
 }
 this.cameraPreview.startRecordVideo(options);
}

停止录制

this.cameraPreview.stopRecordVideo().then((filePath) => {
            alert(JSON.stringify(filePath));
            //filePath = "/data/user/0/com.xyz.abc/cache/fileName.mp4
    });

我没有在该位置获取此文件。我正在使用这个插件:https ://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview 请帮我获取文件。

标签: cordovaionic-frameworkionic5

解决方案


我通过以下方法访问了视频文件:

import { File,FileEntry } from '@ionic-native/file/ngx';

constructor(
    private file: File,
   ) { }
 

this.file.resolveLocalFilesystemUrl("file:///data/user/0/com.xyz.abc/cache/fileName.mp4")
    .then(entry => {
      (<FileEntry>entry).file(file => {


        alert(JSON.stringify(file));
      }
      );
    })
    .catch(err => {
      alert('Error while reading file.' + JSON.stringify(err));
    });

推荐阅读