data(element: any, index: number) {
const m3u8 = this.arrItem[index].name;
const videoSrc = `http://localhost:8080/video/data/${m3u8}`;
if (Hls.isSupported()) {
let hls = new Hls();
hls.loadSource(videoSrc);
hls.attachMedia(element);
hls.on(Hls.Events.MANIFEST_PARSED, function () {
console.log("HLS 加载成功");
element.muted = true;
element.play().catch(err => console.warn("自动播放被阻止:", err));
});
hls.on(Hls.Events.ERROR, function (event, data) {
console.error("HLS 加载错误:", data);
});
hls.on(Hls.Events.FRAG_LOADED, function (event, data) {
console.log("加载 TS 片段:", data.frag.url);
});
} else if (element.canPlayType('application/vnd.apple.mpegurl')) {
element.src = videoSrc;
element.addEventListener('loadedmetadata', function () {
element.muted = true;
element.play();
});
} else {
console.error("当前浏览器不支持 HLS");
}
}
ngAfterViewInit(): void {
this.videoElements.changes.subscribe(() => {
this.videoElements.forEach((video, index) => {
this.data(video.nativeElement, index);
});
});
}`enter code here`
}
enter image description here Why is it that my videos won't play,I use the same code, why can Youdao video play forced back ts files, and Youdao can not play, so my first ts files are 200, and my m3u8 also requested back data?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744310856a4567939.html
评论列表(0条)