mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-15 05:36:17 -08:00
refactor: make html-video-player standalone
This commit is contained in:
1 parent
3335ec529e
commit
1624a3d169
3 files changed
+34
-20
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { MockPipe } from 'ng-mocks';
|
||||
import { TranslatePipe } from '@ngx-translate/core';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { SimpleChange } from '@angular/core';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { TranslatePipe } from '@ngx-translate/core';
|
||||
import { MockPipe } from 'ng-mocks';
|
||||
import { HtmlVideoPlayerComponent } from './html-video-player.component';
|
||||
|
||||
describe('HtmlVideoPlayerComponent', () => {
|
||||
@@ -9,23 +9,18 @@ describe('HtmlVideoPlayerComponent', () => {
|
||||
let fixture: ComponentFixture<HtmlVideoPlayerComponent>;
|
||||
const TEST_CHANNEL = {
|
||||
id: '1234',
|
||||
url: 'http://test',
|
||||
url: 'http://test.ts',
|
||||
name: 'Test channel',
|
||||
group: {
|
||||
title: 'News group',
|
||||
},
|
||||
};
|
||||
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [
|
||||
HtmlVideoPlayerComponent,
|
||||
MockPipe(TranslatePipe),
|
||||
],
|
||||
}).compileComponents();
|
||||
})
|
||||
);
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [HtmlVideoPlayerComponent, MockPipe(TranslatePipe)],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(HtmlVideoPlayerComponent);
|
||||
@@ -45,8 +40,6 @@ describe('HtmlVideoPlayerComponent', () => {
|
||||
});
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.playChannel).toHaveBeenCalledTimes(1);
|
||||
expect(component.playChannel).toHaveBeenCalledWith(TEST_CHANNEL);
|
||||
expect(console.error).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
} from '@angular/core';
|
||||
import Hls from 'hls.js';
|
||||
import { Channel } from '../../../../../shared/channel.interface';
|
||||
import { getExtensionFromUrl } from '../../../../../shared/playlist.utils';
|
||||
|
||||
/**
|
||||
* This component contains the implementation of HTML5 based video player
|
||||
@@ -17,13 +18,14 @@ import { Channel } from '../../../../../shared/channel.interface';
|
||||
selector: 'app-html-video-player',
|
||||
templateUrl: './html-video-player.component.html',
|
||||
styleUrls: ['./html-video-player.component.scss'],
|
||||
standalone: true,
|
||||
})
|
||||
export class HtmlVideoPlayerComponent implements OnChanges, OnDestroy {
|
||||
/** Channel to play */
|
||||
@Input() channel: Channel;
|
||||
|
||||
/** Video player DOM element */
|
||||
@ViewChild('videoPlayer', { static: false })
|
||||
@ViewChild('videoPlayer', { static: true })
|
||||
videoPlayer: ElementRef<HTMLVideoElement>;
|
||||
|
||||
/** HLS object */
|
||||
@@ -49,8 +51,14 @@ export class HtmlVideoPlayerComponent implements OnChanges, OnDestroy {
|
||||
playChannel(channel: Channel): void {
|
||||
if (this.hls) this.hls.destroy();
|
||||
if (channel.url) {
|
||||
const url = channel.url + channel.epgParams;
|
||||
if (Hls && Hls.isSupported()) {
|
||||
const url = channel.url + (channel.epgParams ?? '');
|
||||
const extension = getExtensionFromUrl(channel.url);
|
||||
if (
|
||||
extension !== 'mp4' &&
|
||||
extension !== 'mpv' &&
|
||||
Hls &&
|
||||
Hls.isSupported()
|
||||
) {
|
||||
console.log('... switching channel to ', channel.name, url);
|
||||
this.hls = new Hls();
|
||||
this.hls.attachMedia(this.videoPlayer.nativeElement);
|
||||
@@ -58,10 +66,23 @@ export class HtmlVideoPlayerComponent implements OnChanges, OnDestroy {
|
||||
this.handlePlayOperation();
|
||||
} else {
|
||||
console.error('something wrong with hls.js init...');
|
||||
this.addSourceToVideo(
|
||||
this.videoPlayer.nativeElement,
|
||||
url,
|
||||
'video/mp4'
|
||||
);
|
||||
this.videoPlayer.nativeElement.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addSourceToVideo(element: HTMLVideoElement, url: string, type: string) {
|
||||
const source = document.createElement('source');
|
||||
source.src = url;
|
||||
source.type = type;
|
||||
element.appendChild(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables text based captions based on the global settings
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,7 @@ const routes: Routes = [{ path: '', component: VideoPlayerComponent }];
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
HtmlVideoPlayerComponent,
|
||||
OverlayModule,
|
||||
RouterModule.forChild(routes),
|
||||
SharedModule,
|
||||
@@ -33,7 +34,6 @@ const routes: Routes = [{ path: '', component: VideoPlayerComponent }];
|
||||
EpgListComponent,
|
||||
EpgListItemComponent,
|
||||
InfoOverlayComponent,
|
||||
HtmlVideoPlayerComponent,
|
||||
MultiEpgContainerComponent,
|
||||
SidebarComponent,
|
||||
ToolbarComponent,
|
||||
|
||||
Reference in new issue
Block a user