首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Chrome上使用Shaka播放器播放HLS m3u8

在Chrome上使用Shaka播放器播放HLS m3u8
EN

Stack Overflow用户
提问于 2020-06-26 22:13:02
回答 2查看 2.5K关注 0票数 1

我遵循shaka的基本用法来处理DASH视频,但在尝试加载M3U8时抛出了一个错误代码4032。

代码语言:javascript
复制
import * as muxjs from 'mux.js';
import * as shaka from 'shaka-player';

export class AppComponent implements AfterViewInit {
  @ViewChild('videoPlayer') videoElementRef: ElementRef;
  videoElement: HTMLVideoElement;

  manifestUri = 'http://hlsliveamdgl7-lh.akamaihd.net/i/hlsdvrlive_1@583042/master.m3u8';


  ngAfterViewInit() {
    shaka.polyfill.installAll();
    this.videoElement = this.videoElementRef.nativeElement;
    this.initPlayer();
  }

  private initPlayer() {
    shaka.media.ManifestParser.registerParserByExtension("m3u8", shaka.hls.HlsParser);
    shaka.media.ManifestParser.registerParserByMime("Application/vnd.apple.mpegurl", shaka.hls.HlsParser);
    shaka.media.ManifestParser.registerParserByMime("application/x-mpegURL", shaka.hls.HlsParser);


    let player = new shaka.Player(this.videoElement);


    player.load(this.manifestUri).then(() => {
      // This runs if the asynchronous load is successful.
      console.log('The video has now been loaded!');
    }).catch(this.onError);  // onError is executed if the asynchronous load fails.
  }

模板是

代码语言:javascript
复制
  <video #videoPlayer
     id="video"
     width="640"
     poster="https://upload.wikimedia.org/wikipedia/commons/c/c4/PM5544_with_non-PAL_signals.png"
     controls> </video>

相关的Angular 9依赖项包括

代码语言:javascript
复制
 "shaka-player": "^3.0.1",

并且还安装了(可能不需要)

代码语言:javascript
复制
"hls.js": "^0.13.2",
"mux.js": "^5.6.4",

它可以在Safari上运行,但在Chrome上就不行。我想我遗漏了一些与mux.js相关的东西。

有什么提示吗?非常感谢!

EN

回答 2

Stack Overflow用户

发布于 2020-06-26 23:03:45

事实证明,它只需添加以下内容即可工作

<script src="https://github.com/videojs/mux.js/releases/latest/download/mux.js"></script>

到Angular的index.html。导入不起作用。不需要进行额外的配置。Shaka会检测到它并使用它。

而是因为我想要keep the dependency inside the app。我将js复制到assets文件夹(as referencing from node modules does not work

代码语言:javascript
复制
<script defer src="assets/mux.min.js"></script>

遗憾的是,从angular.json脚本引用也不起作用。

票数 4
EN

Stack Overflow用户

发布于 2021-01-06 17:19:34

尝试对import执行此操作以保留依赖关系:

代码语言:javascript
复制
import muxjs from 'mux.js';

interface MyWindow extends Window {
    muxjs: string;
}

(window as MyWindow & typeof globalThis).muxjs = muxjs;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62596654

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档