Angular 9 中的视频 JS - 实时视频 - “无法解决 videojs”问题?

2023-12-26

我正在努力让 videojs 在我的 Angular 9 应用程序中工作。我已经查看了所有现有的 stackoverflow 帖子,应用了他们的解决方案,查看了不同的博客文章和 github 来了解视频 js 的问题,但我仍然遇到“无法解决 videojs”问题。

我希望它的工作原理是,查看该页面的个人可以开始录制自己的视频。

有人可以建议吗?请看下面我的代码@

我的 package.json 文件:

{
  "name": "post-stroke-care-project",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~9.1.9",
    "@angular/common": "~9.1.9",
    "@angular/compiler": "~9.1.9",
    "@angular/core": "~9.1.9",
    "@angular/forms": "~9.1.9",
    "@angular/platform-browser": "~9.1.9",
    "@angular/platform-browser-dynamic": "~9.1.9",
    "@angular/router": "~9.1.9",
    "@fortawesome/angular-fontawesome": "^0.6.1",
    "@fortawesome/fontawesome-svg-core": "^1.2.29",
    "@fortawesome/free-brands-svg-icons": "^5.13.1",
    "@fortawesome/free-regular-svg-icons": "^5.13.1",
    "@fortawesome/free-solid-svg-icons": "^5.13.1",
    "@fullcalendar/angular": "^5.1.0",
    "@fullcalendar/daygrid": "^5.1.0",
    "@fullcalendar/interaction": "^5.1.0",
    "@types/video.js": "^7.3.10",
    "angular-google-charts": "^1.1.4",
    "bootstrap": "^4.5.0",
    "core-js": "^3.6.5",
    "fullcalendar": "^5.1.0",
    "html-webpack-plugin": "^4.3.0",
    "jquery": "^3.5.1",
    "moment": "^2.27.0",
    "ngx-build-plus": "^10.1.1",
    "popper.js": "^1.16.1",
    "raw-loader": "^4.0.1",
    "rxjs": "~6.5.4",
    "rxjs-compat": "^6.6.0",
    "ts-loader": "^8.0.1",
    "tslib": "^1.10.0",
    "video.js": "^7.8.4",
    "videojs-record": "^4.0.0",
    "webpack": "^4.44.0",
    "webpack-cli": "^3.3.12",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.901.7",
    "@angular/cli": "~9.1.7",
    "@angular/compiler-cli": "~9.1.9",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.12.53",
    "codelyzer": "^5.1.2",
    "jasmine": "^3.6.1",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~5.0.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~3.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~3.8.3",
    "webpack-dev-server": "^3.11.0"
  }
}

webpack.config.js 文件:

const HtmlWebpackPlugin = require('html-webpack-plugin');
const ProvidePlugin = require('webpack/lib/ProvidePlugin');

module.exports = {
    entry: './src/main.ts',
    resolve: {
        extensions: ['.ts', '.js'],
        alias: {
            videojs: 'video.js',
            WaveSurfer: 'wavesurfer.js',
            RecordRTC: 'recordrtc'
        }
    },
    module: {
        rules: [
            {
                test: /\.ts$/,
                use: ['ts-loader']
            },
            {
                test: /\.(html|css)$/,
                use: 'raw-loader'
            }
        ]
    },
    plugins: [
        new ProvidePlugin({
            videojs: 'video.js/dist/video.cjs.js',
            RecordRTC: 'recordrtc'
        }),
        new HtmlWebpackPlugin({ template: './src/index.html' })
    ]
}

视频组件.ts 文件:

import {
    Component,
    OnInit,
    OnDestroy,
    ElementRef
  } from '@angular/core';
  
  import videojs from 'video.js';
  import * as adapter from 'webrtc-adapter/out/adapter_no_global.js';
  import * as RecordRTC from 'recordrtc';
  
  
  import * as Record from 'videojs-record/dist/videojs.record.js';
  
  @Component({
    selector: 'videojs-record',
    template: `
      <style>
      /* change player background color */
      .video-js video {
           background-color: #42f489;
      }
      </style>
      <video id="video_{{idx}}" class="video-js vjs-default-skin" playsinline></video>
      `
  })
  
  export class VideorComponent implements OnInit, OnDestroy {
  
    // reference to the element itself: used to access events and methods
    private _elementRef: ElementRef
  
    // index to create unique ID for component
    idx = 'clip1';
  
    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,
        bigPlayButton: false,
        controlBar: {
          volumePanel: false
        },
        plugins: {
          /*
          // wavesurfer section is only needed when recording audio-only
          wavesurfer: {
              backend: 'WebAudio',
              waveColor: '#36393b',
              progressColor: 'black',
              debug: true,
              cursorWidth: 1,
              displayMilliseconds: true,
              hideScrollbar: true,
              plugins: [
                  // enable microphone plugin
                  WaveSurfer.microphone.create({
                      bufferSize: 4096,
                      numberOfInputChannels: 1,
                      numberOfOutputChannels: 1,
                      constraints: {
                          video: false,
                          audio: true
                      }
                  })
              ]
          },
          */
          // 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;
      }
    }
  
  }

视频组件.html 文件:

<!DOCTYPE html>
<html>
<head>
    <base href="/" />
    <title>Angular videojs-record example</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <!-- styles -->
    <link href="node_modules/video.js/dist/video-js.css" rel="stylesheet">
    <!-- videojs.wavesurfer.css is only required when recording audio-only
    <link href="node_modules/videojs-wavesurfer/dist/css/videojs.wavesurfer.css" rel="stylesheet">
    -->
    <link href="node_modules/videojs-record/dist/css/videojs.record.css" rel="stylesheet">
</head>
<body>
    <videojs-record></videojs-record>
</body>
</html>

webpack.externals.js:

const webpack = require('webpack');
module.exports = {
    "externals": {
        "rxjs": "rxjs",
        "@angular/core": "ng.core",
        "@angular/common": "ng.common",
        "@angular/common/http": "ng.common.http",
        "@angular/platform-browser": "ng.platformBrowser",
        "@angular/platform-browser-dynamic": "ng.platformBrowserDynamic",
        "@angular/compiler": "ng.compiler",
        "@angular/elements": "ng.elements",

        // Uncomment and add to scripts in angular.json if needed
        // "@angular/router": "ng.router",
        // "@angular/forms": "ng.forms"
    }
}

错误消息:错误:无法解析“C:\Users\learnerA\中风护理项目\node_modules\videojs-record\dist”中的“videojs”

update(写在这里@tmhao2005,因为我无法将其全部放入评论部分) 应用您的解决方案并指定 webpack 配置名称后,我收到一条错误消息

WARNING in C:\Users\j\post-stroke-care-project\src\polyfills.ts is part of the TypeScript compilation but it's unused.
Add only entry points to the 'files' or 'include' properties in your tsconfig.

根据您的建议,我已删除“entry: './src/main.ts'”,但它没有进行任何更改。

请在更新后查看我的代码(我已经安装了您建议的软件包):

角度.json 文件:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "post-stroke-care-project": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-builders/custom-webpack:browser",
          "options": {
            "customWebpackConfig":{
              "path":"./webpack.config.js"
            },
            "outputPath": "dist/post-stroke-care-project",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss",
              "node_modules/fullcalendar/main.min.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js",
              "node_modules/moment/min/moment.min.js",
              "node_modules/fullcalendar/main.min.js",
              {
                "bundleName": "polyfill-webcomp-es5",
                "input": "node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"
              },
              {
                "bundleName": "polyfill-webcomp",
                "input": "node_modules/@webcomponents/webcomponentsjs/bundles/webcomponents-sd-ce-pf.js"
              },
              "node_modules/rxjs/bundles/rxjs.umd.js",
              "node_modules/@angular/core/bundles/core.umd.js",
              "node_modules/@angular/common/bundles/common.umd.js",
              "node_modules/@angular/common/bundles/common-http.umd.js",
              "node_modules/@angular/compiler/bundles/compiler.umd.js",
              "node_modules/@angular/platform-browser/bundles/platform-browser.umd.js",
              "node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js"
            ]
            
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }

          }
        },
        "serve": {
          "builder": "@angular-builders/custom-webpack:dev-server",
          "options": {
            "browserTarget": "post-stroke-care-project:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "post-stroke-care-project:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "post-stroke-care-project:build"
          }
        },
        "test": {
          "builder": "ngx-build-plus:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "post-stroke-care-project:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "post-stroke-care-project:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "post-stroke-care-project"
}

tsconfig.app.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts",
    
  ]
  
}

我认为问题是你的webpack.alias不受影响。另一方面,你的webpack.config.js尚未应用。这是为您提供的解决方案:

  • 安装以下软件包,使您能够自定义webpack:
npm i -D @angular-builders/custom-webpack @angular-builders/dev-server
  • In angular.json文件,然后更改构建器@angular-devkit/build-angular:browser to @angular-builders/custom-webpack:browser并添加customWebpackConfig:
"build": {
  "builder": "@angular-builders/custom-webpack:browser",
  "options": {
    "customWebpackConfig": {
      // path to your webpack config
      "path": "./webpack.config.js"
    }
  }
}
  • Also in angular.json,替换值build财产来自@angular-devkit/build-angular:dev-server to @angular-builders/custom-webpack:dev-server under serve block.
"serve": {
  "builder": "@angular-builders/custom-webpack:dev-server",
}

关于您的webpack.config.js,解决问题的最少代码是设置别名video.js -> videojs since videojs-record需要模块videojs:

module.exports = {
  resolve: {
    alias: {
      videojs: 'video.js'
    }
  },
}

就是这样!希望它能帮助解决您的问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Angular 9 中的视频 JS - 实时视频 - “无法解决 videojs”问题? 的相关文章

随机推荐

  • Unity,如何将精灵设置在背景图像前面?

    我制作了背景图像并运行动画 问题是动画层位于背景图像后面 怎么排序呢 信息 见截图 背景图像 z 0 图片上的绿色 GUITexture 爆炸 z 5 图片上的黄色 精灵渲染器 相机 z 10 我尝试过反转数字 但仍然一样 我还尝试在背景图
  • 包裹

    我有来自数据库的项目列表 ul li Jon Skeet li li Darin Dimitrov li li Marc Gravell li li BalusC li li Hans Passant li li SLaks li li V
  • 抓取:http://en.wikipedia.org 的 SSL: CERTIFICATE_VERIFY_FAILED 错误

    我正在练习 Web Scraping with Python 中的代码 但我一直遇到此证书问题 from urllib request import urlopen from bs4 import BeautifulSoup import
  • 无法在Python中使用Selenium访问下拉选择

    我是在 Python 中使用 Selenium 的新手 我正在尝试访问 Barclays Live 网站上的索引数据 登录并加载页面后 我尝试从页面的下拉列表中选择 Custom1 与列表关联的 HTML 代码中的选择对象如下所示
  • 检查软盘驱动器

    获取我使用过的可移动驱动器获取驱动器类型 功能 是否可以检查驱动器是否是软盘驱动器 请让我知道您对此的建议 感谢您的任何帮助 在内部 Microsoft Windows 为每个设备保存命名的特征标志 在 wdm h 中定义 如果该盘符对应的
  • Android VR工具包-HeadTransform getHeadView矩阵表示

    我从适用于谷歌纸板的 Android VR Toolkit 开始 我使用谷歌网站上的示例 https developers google com cardboard get started https developers google c
  • 音频标签持续时间属性返回“无穷大”

    它可能是重复的 但我有一个非常奇怪的场景 用例是在播放音频之前动态显示源集的音频持续时间 这是我到目前为止所尝试过的 var tempVid document 0 createElement audio tempVid preload me
  • CollapsingToolbarLayout:类似于 Facebook 的自定义 contentScrim

    我想为我的产品创建一个自定义 contentScrimcollapsingToolbarLayout 我的 collapsingToolbarLayout 有一个imageview里面 当它滚动时 理论上图像视图应该淡出 而我的稀松布颜色应
  • 显示加载窗口

    我在 WPF 中的应用程序加载外部资源 因此我想在程序加载时显示加载表单 我尝试创建表单 并在加载代码之前显示 并在加载结束时关闭 private void Window Loaded object sender RoutedEventAr
  • 本地Tomcat环境未启动

    我正在尝试运行本地 Tomcat 环境 但始终遇到以下错误 Can t load log handler 2localhost org apache juli FileHandler java lang ClassNotFoundExcep
  • 使用 fread() 将文本文件读入缓冲区 - 为什么缓冲区中的值不是每个字符各自的 ASCII 值?

    首先 这不是家庭作业 只是想了解为什么我会在屏幕上看到这些内容 下面的内容 我自己的工作 当前采用输入文件并将其作为二进制文件读取 我希望它将读取的每个字节存储在数组中 以供以后使用 为了简洁起见 输入文件 Hello txt 仅包含 He
  • ALV 列表中的两级列标题

    我想添加一个标题行来对列标题进行分组 Departure Arrival lt This row is what I want to add Airport Gate Date Airport Gate Date O Hare A10 10
  • 手机端口0接收短信

    我正在将 J2ME 应用程序配置为在收到 SMS 时从推送注册表获取事件 在 SMS 消息到达收件箱之前 我能否访问该消息 我读到发送到移动设备 port0 的消息会直接发送到本机收件箱 我们无法访问它 是否有任何方法可以转移甚至嗅探这些消
  • 单个应用程序窗口的任务管理器中 Visual Studio Code 的多个实例或进程

    我正在使用 Visual Studio 代码 我的机器面临性能问题 我去了任务管理器 看到有几个实例Code exe在进程选项卡中 即使有only我的电脑上正在运行 活动的 Visual Studio Code 的一个窗口 我可以看到总共有
  • 以编程方式编写 gui,还是使用高级 gui 编辑器(Java Swing)?

    我计划编写一个基于 Swing 的应用程序 使用 Netbeans 6 8 看来 Netbeans 有一个非常先进的 GUI 编辑器 我仍然对它生成的代码存有疑问 另外 我不喜欢代码部分被锁定的事实 我仍然理解这种需要 有人成功使用 Net
  • DbConnectionStringBuilder 在 PowerShell 中使用时不会解析

    我正在尝试使用以下功能DbConnectionStringBuilder用于解析类似连接字符串的用户输入 这在 C 中工作得很好 using System using System Data Common class Program sta
  • postgresql - 查询构建 json

    运行 PostgreSQL 9 6 2 我的数据以键 值对的形式存储在表中 key 实际上是一个json对象的路径 每一个都是一个属性 例如 如果键是 cogs props1 value 那么 json 对象将如下所示 cogs props
  • Python-将脚本安装到系统

    如何为我自己的脚本制作 setup py 文件 我必须使我的脚本全球化 将其添加到 usr bin 这样我就可以从控制台运行它 只需键入 scriptName 参数 操作系统 Linux EDIT 现在我的脚本可以安装了 但是如何使其全局化
  • JavaScript 立即函数

    Stoyan Stefanov 在 Javascript Patterns 中说道 你需要一个即时函数来将所有代码包装在其本地作用域中 并且不会将任何变量泄漏到全局作用域 第 70 页 这是他的例子 function var days Su
  • Angular 9 中的视频 JS - 实时视频 - “无法解决 videojs”问题?

    我正在努力让 videojs 在我的 Angular 9 应用程序中工作 我已经查看了所有现有的 stackoverflow 帖子 应用了他们的解决方案 查看了不同的博客文章和 github 来了解视频 js 的问题 但我仍然遇到 无法解决