【问题标题】:is anyone integrated videojs-record with angular 7?有人将 videojs-record 与 Angular 7 集成在一起吗?
【发布时间】:2020-08-07 13:54:46
【问题描述】:

我正在尝试使用 videojs-record 录制带有音频的视频,而我的应用程序是 Angular 7。我已经关注了他们的 wiki。这是下面的链接 https://github.com/collab-project/videojs-record/wiki/Angular 但这对我不起作用。

这是我得到的错误

ERROR in ./node_modules/videojs-record/dist/videojs.record.js
Module not found: Error: Can't resolve 'RecordRTC' in '/path/to/project/root/node_modules/videojs-record/dist'
ERROR in ./node_modules/videojs-record/dist/videojs.record.js
Module not found: Error: Can't resolve 'videojs' in '/path/to/project/root/node_modules/videojs-record/dist'

这是我在 video-recorder.component.ts 中对 videojs 的代码和配置

import { Component, OnInit, OnDestroy, ElementRef, Input } from '@angular/core';
import videojs from 'video.js';
import * as adapter from 'webrtc-adapter/out/adapter_no_global.js';
import * as RecordRTC from 'recordrtc';

// register videojs-record plugin with this import
import * as Record from 'videojs-record/dist/videojs.record.js';

@Component({
  selector: 'app-video-recorder',
  templateUrl: './video-recorder.component.html',
  styleUrls: ['./video-recorder.component.scss']
})
export class VideoRecorderComponent implements OnInit, OnDestroy {
  // reference to the element itself: used to access events and methods
  private _elementRef: ElementRef;

  // index to create unique ID for component
  @Input() idx: string;

  private config: any;
  private player: any; 
  private plugin: any;

  // constructor initializes our declared vars
  constructor(elementRef: ElementRef) {
    this.player = false;

    // save reference to plugin (so it initializes)
    this.plugin = Record;

    // video.js configuration
    this.config = {
      controls: true,
      autoplay: false,
      fluid: false,
      loop: false,
      width: 320,
      height: 240,
      controlBar: {
        volumePanel: false
      },
      plugins: {
        // configure videojs-record plugin
        record: {
          audio: false,
          video: true,
          debug: true
        }
      }
    };
  }

  ngOnInit() {}

  // use ngAfterViewInit to make sure we initialize the videojs element
  // after the component template itself has been rendered
  ngAfterViewInit() {
    // ID with which to access the template's video element
    let el = 'video_' + this.idx;

    // setup the player via the unique element ID
    this.player = videojs(document.getElementById(el), this.config, () => {
      console.log('player ready! id:', el);

      // print version information at startup
      var msg = 'Using video.js ' + videojs.VERSION +
        ' with videojs-record ' + videojs.getPluginVersion('record') +
        ' and recordrtc ' + RecordRTC.version;
      videojs.log(msg);
    });

    // device is ready
    this.player.on('deviceReady', () => {
      console.log('device is ready!');
    });

    // user clicked the record button and started recording
    this.player.on('startRecord', () => {
      console.log('started recording!');
    });

    // user completed recording and stream is available
    this.player.on('finishRecord', () => {
      // recordedData is a blob object containing the recorded data that
      // can be downloaded by the user, stored on server etc.
      console.log('finished recording: ', this.player.recordedData);
    });

    // error handling
    this.player.on('error', (element, error) => {
      console.warn(error);
    });

    this.player.on('deviceError', () => {
      console.error('device error:', this.player.deviceErrorCode);
    });
  }

  // use ngOnDestroy to detach event handlers and remove the player
  ngOnDestroy() {
    if (this.player) {
      this.player.dispose();
      this.player = false;
    }
  }

}

这是我的 video-recorder.component.html

<video id="video_{{idx}}" class="video-js vjs-default-skin" playsinline></video>

以下信息可能有助于解决问题。

Angular CLI: 7.2.3
Node: 10.15.1
OS: linux x64
Angular: 7.2.2
... common, compiler, core, forms, language-service
... platform-browser, platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.12.3
@angular-devkit/build-angular     0.12.3
@angular-devkit/build-optimizer   0.12.3
@angular-devkit/build-webpack     0.12.3
@angular-devkit/core              7.2.3
@angular-devkit/schematics        7.2.3
@angular/animations               7.2.7
@angular/cdk                      7.3.0
@angular/cli                      7.2.3
@angular/compiler-cli             7.2.7
@ngtools/webpack                  7.2.3
@schematics/angular               7.2.3
@schematics/update                0.12.3
rxjs                              6.3.3
typescript                        3.2.4

我是 Angular 的新手。因此,对此的任何帮助将不胜感激。提前致谢。

【问题讨论】:

  • 这不是一个论坛,也不是做这些事情的平台。在 SO 上,您要针对特定​​的编程问题提出特定的问题,最好使用代码来生成可以解决您的问题的答案。 stackoverflow.com/help/on-topic
  • @Rob 如你所问,我已在我的代码中添加了详细信息

标签: angular7 video.js videojs-record


【解决方案1】:

别担心,我已经自己修好了。在做了一些研究之后,我开始知道,由于我使用 angular cli 来服务和构建,所以我使用了 ngx-build-plus(因为 ng eject 在 angular 7 中已弃用,并将从 angular 8 中删除)来使用 angular 执行 webpack 配置cli。这个 webpack 配置以前是丢失的。这可能对刚刚分享的人有所帮助。谢谢。

【讨论】:

  • 你能分享一下你是怎么做的吗?使用 ngx-build-plus 的过程是怎样的?
  • 您好,根据前面的发言者,您能解释一下您是如何找到解决方案的吗?请在此处查看我的问题 Video JS in Angular 9 - live video - 'Can't resolve videojs' 问题? ,不知道哪里出错了,因为我有一个网络配置文件
  • @Subhadip Sahoo。你能在 Safari 浏览器上录制视频吗?
【解决方案2】:

你不能那样使用。如果您使用 Angular cli 服务或构建,那么您必须创建一个部分 webpack 配置文件并通过 angular cli 服务或构建它。您应该遵循以下事项。

请访问以下链接并安装软件包并按照说明配置您的东西。

https://www.npmjs.com/package/ngx-build-plus

你的webpack.partial.js 应该是这样的

const webpack = require('webpack');

module.exports = {
    resolve: {
        alias: {
            // place your config
        }
    },
    plugins: [
        // place your config
    ],

}

package.json 文件中的scripts 应该看起来像

"scripts": {
    "ng": "ng",
    "start": "ng serve --extra-webpack-config webpack.partial.js",
    "build": "ng build --extra-webpack-config webpack.partial.js",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "build:prod": "ng build --prod --extra-webpack-config webpack.partial.js",
    "build:stage": "ng build --prod -c staging --extra-webpack-config webpack.partial.js",
    "build:dev": "ng build -c development --extra-webpack-config webpack.partial.js"
  },

然后您可以使用npm start 为您的应用提供服务 要构建您,请使用npm run build:dev || npm run build:stage || npm run build:prod 视环境而定。

【讨论】:

  • 谢谢!我设法使用以下 webpack 配置文件来做到这一点:``` const webpack = require("webpack"); module.exports = { resolve: { alias: { videojs: "video.js", WaveSurfer: "wavesurfer.js", RecordRTC: "recordrtc" } } }; ```
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-16
  • 2020-10-18
  • 1970-01-01
  • 2018-01-11
  • 2016-02-04
  • 2014-06-08
相关资源
最近更新 更多