我正在尝试通过cordova插件Media Capture在我的应用程序中注册视频。根据文档,这是我的代码:
startRegistration(){
var captureSuccess = function(mediaFiles) {
var i, path, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
path = mediaFiles[i].fullPath;
// do something interesting with the file
}
};
// capture error callback
var captureError = function(error) {
};
navigator.device.capture.captureVideo(captureSuccess, captureError, {limit:1});
}
我尝试编译代码,但收到以下错误:
Property 'device' does not exist on type 'Navigator'
出了什么问题?
答案 0 :(得分:0)
它曾经在Ionic 1中像这样工作,但现在已经不复存在了。现在,您还需要安装@ionic-native/media-capture
。
如果已经安装了最新的插件,请跳过第一个命令。
ionic cordova plugin add cordova-plugin-media-capture
npm install @ionic-native/media-capture
安装后,您可以像这样使用此插件
import { MediaCapture, MediaFile, CaptureError, CaptureImageOptions } from '@ionic-native/media-capture/ngx';
constructor(private mediaCapture: MediaCapture) { }
...
let options: CaptureImageOptions = { limit: 3 }
this.mediaCapture.captureImage(options)
.then(
(data: MediaFile[]) => console.log(data),
(err: CaptureError) => console.error(err)
);
Here is the link where you can find details
Corodva
或Capacitor
,请相应执行。您可以在此链接中找到这两个指南。