Files
iptvnator/libs/ui/shared-portals/src/lib/web-player-view/web-player-view.component.ts
T
markc1984 e3d1bf2048 fix: support raw MPEG-TS (.ts) streams in all embedded video players
Xtream Codes live streams with .ts format serve continuous raw MPEG-TS
data over HTTP, not HLS playlists. All three embedded players failed to
handle this: ArtPlayer had no handler, HTML5 player fed it to HLS.js,
and Video.js tried to parse it as an HLS manifest.

Add mpegts.js to handle raw MPEG-TS streams via Media Source Extensions
in ArtPlayer, HTML5 player, and Video.js. Fix the MIME type for .ts
sources from application/x-mpegURL to video/mp2t.
2026-03-03 06:47:34 +00:00

76 lines
2.0 KiB
TypeScript

import {
Component,
EventEmitter,
Output,
Signal,
ViewEncapsulation,
effect,
inject,
input,
} from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { StorageMap } from '@ngx-pwa/local-storage';
import {
ArtPlayerComponent,
HtmlVideoPlayerComponent,
VjsPlayerComponent,
} from 'components';
import { getExtensionFromUrl } from 'm3u-utils';
import { STORE_KEY, Settings, VideoPlayer } from 'shared-interfaces';
@Component({
selector: 'app-web-player-view',
templateUrl: './web-player-view.component.html',
styleUrls: ['./web-player-view.component.scss'],
imports: [ArtPlayerComponent, HtmlVideoPlayerComponent, VjsPlayerComponent],
encapsulation: ViewEncapsulation.None,
})
export class WebPlayerViewComponent {
storage = inject(StorageMap);
streamUrl = input.required<string>();
startTime = input<number>(0);
@Output() timeUpdate = new EventEmitter<{
currentTime: number;
duration: number;
}>();
settings = toSignal(
this.storage.get(STORE_KEY.Settings)
) as Signal<Settings>;
channel!: { url: string };
player!: VideoPlayer;
vjsOptions!: { sources: { src: string; type: string }[] };
constructor() {
effect(() => {
this.player = this.settings()?.player;
this.setChannel(this.streamUrl());
if (this.player === VideoPlayer.VideoJs)
this.setVjsOptions(this.streamUrl());
});
}
setVjsOptions(streamUrl: string) {
const extension = getExtensionFromUrl(streamUrl);
const mimeType =
extension === 'm3u' || extension === 'm3u8'
? 'application/x-mpegURL'
: extension === 'ts'
? 'video/mp2t'
: 'video/mp4';
this.vjsOptions = {
sources: [{ src: streamUrl, type: mimeType }],
};
}
setChannel(streamUrl: string) {
this.channel = {
url: streamUrl,
};
}
}