Ionic 离子v5网络媒体捕获与电容器- cordova _不可用

x4shl7ld  于 2023-01-15  发布在  Ionic
关注(0)|答案(1)|浏览(118)

我正在构建一个应用程序与离子5,电容器2和Angular 11。我需要捕捉视频和音频使用the media capture cordova plugin
我安装了以下模块:

npm install cordova-plugin-media-capture
npm install @ionic-native/media-capture

并将MediaCapture添加到我的应用模块的提供者中,然后我调用 mediaCapture.captureVideo() 来获取一个视频;不幸的是,在浏览器上测试时会抛出异常:cordova_not_available
The github repo声明此插件是web兼容的,并且它的源代码有浏览器实现。但是window.navigator.device.capture缺失,无法使此插件工作。

是我的配置不好吗?还是这个cordova插件与capacitor不兼容?

我做了一个复制:https://stackblitz.com/edit/ionic-v5-media-capture-capacitor?file=src/app/app.component.ts
谢谢你的帮忙

ztigrdn8

ztigrdn81#

我写了一个常规的Angular 版本的网络,如果有人需要它:

async browserCapture() {
  const stream: MediaStream = await navigator.mediaDevices.getUserMedia(this.constraints);
  const recorder = new MediaRecorder(stream, {mimeType: 'ogg'});
  const chunks: Blob[] = [];
  recorder.ondataavailable = (event: BlobEvent) => {
    if (event.data && event.data.size > 0) {
      chunks.push(event.data);
      this.zone.run(() => {
        this.recordChunks = [...chunks];
        this.cd.markForCheck();
      });
    }
  };
  this.recorder.onstop = () => {
    this.zone.run(() => {
      stream.getTracks().forEach(t => t.stop());
      if (chunks?.length) {
        this.upload(new Blob(chunks, {type: 'ogg'})); // use the blob result
      }
    });
  };
  recorder.start(500);
}

相关问题