gpt4 book ai didi

angular - 在 Chrome 上使用 Shaka Player 播放 HLS m3u8

转载 作者:行者123 更新时间:2023-12-01 23:57:06 27 4
gpt4 key购买 nike

我遵循与 DASH 视频一起使用的 shaka 的基本用法,但在尝试加载 M3U8 时抛出错误代码 4032。

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.
}

模板是

  <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 依赖项是

 "shaka-player": "^3.0.1",

并且还安装了(可能是不必要的)

"hls.js": "^0.13.2",
"mux.js": "^5.6.4",

它在 Safari 上有效,但在 Chrome 上无效。我想我遗漏了一些与 mux.js 相关的东西。

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

最佳答案

事实证明,只需添加这个就可以了

<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

<script defer src="assets/mux.min.js"></script>

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

关于angular - 在 Chrome 上使用 Shaka Player 播放 HLS m3u8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62596654/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com