fix: promise issue after channel switch #29

this commit closes #29
This commit is contained in:
4gray committed 2021-05-18 21:00:46 +02:00
1 parent 6b2c6158a5
commit d1f194a25e
1 file changed
+17 -2
@@ -46,7 +46,7 @@ export class HtmlVideoPlayerComponent implements OnChanges, OnDestroy {
console.log('... switching channel to ', channel.name, url); console.log('... switching channel to ', channel.name, url);
this.hls.loadSource(url); this.hls.loadSource(url);
this.hls.attachMedia(this.videoPlayer.nativeElement); this.hls.attachMedia(this.videoPlayer.nativeElement);
this.videoPlayer.nativeElement.play(); this.handlePlayOperation();
} else if ( } else if (
this.videoPlayer.nativeElement.canPlayType( this.videoPlayer.nativeElement.canPlayType(
'application/vnd.apple.mpegurl' 'application/vnd.apple.mpegurl'
@@ -56,12 +56,27 @@ export class HtmlVideoPlayerComponent implements OnChanges, OnDestroy {
this.videoPlayer.nativeElement.addEventListener( this.videoPlayer.nativeElement.addEventListener(
'loadedmetadata', 'loadedmetadata',
() => { () => {
this.videoPlayer.nativeElement.play(); this.handlePlayOperation();
} }
); );
} }
} }
/**
* Handles promise based play operation
*/
handlePlayOperation(): void {
const playPromise = this.videoPlayer.nativeElement.play();
if (playPromise !== undefined) {
playPromise
.then(() => {
// Automatic playback started!
})
.catch((error) => console.error(error));
}
}
/** /**
* Destroy hls instance on component destroy * Destroy hls instance on component destroy
*/ */