videogular2
videogular2 copied to clipboard
Which event do i need to capture when the video is cancelled without being ended
Hi, First thumbs up to the work put on this great library.
I am having trouble which event to capture when the video is canceled without ending. I want to implement a resume video feature. and i need to capture the event when a user decides to cancel the video without the video being ended.
Any pointers would be really helpful.
Thanks in advance
@akamanzi how can a user "cancel" a video?
@Elecash, what i meant is when a user presses the browser back button when the video is not yet ended
@akamanzi In my opinion, that's not Videogulars's job to provide these events, but you can handle this by angular itself.
First of all, you need to decide what kind of event you want to handle. a) Close/refresh tab or browser b) Naviagtion changed
a) Listen to the host event window:beforeunload
@HostListener('window:beforeunload', ['$event']) saveVideoPlayback($event: any) { this.videoResumeService.pushVideo(videoId, position); }
b) You need to implement your own CanDeactivate-Guard see Angular-Documentation
@ViktorReib Thanks for the help and pointers. Let me definitely try to implement this.
@Elecash, @ViktorReib I am trying to setup the currentTime manually using the API, in firefox it is working fine but with Chrome it is not. What am i doing wrong? Below is the code snippet
this.api.getDefaultMedia().currentTime = 120;
Thanks in advance
Did you read the manual page using-the-api? This works for me:
onPlayerReady(api:VgAPI) {
this.api = api;
this.api.getDefaultMedia().currentTime = 5;
}
Chrome 70.0.3538.110 Firefox 63.0.3
@ViktorReib, I am using the exact same code but for some reasons in is not working in chrome. With firefox it is working fine but with chrome it is not. Below is the code snippet
onPlayerReady(api: VgAPI, fullscreen: VgFullscreenAPI) {
this.api = api;
this.api.getDefaultMedia().subscriptions.loadedMetadata.subscribe(
() => {
this.data.checkBalance().subscribe(response => {
console.log("response", response)
if (response['success']){
if (this.api.getDefaultMedia().canPlayThrough){
this.api.getDefaultMedia().currentTime = 120;
}
}
})
}
);
}
Chrome 70.0.3538.110 Firefox 63.0.3
Could you please provide an stackblitz example? I think the mistake will have been hidden in the details :)