nativescript-youtubeplayer
nativescript-youtubeplayer copied to clipboard
How can I destroy the player in Angular?
Is there a way for me to remove this player when exiting the page as it seems to be crashing the app when I go back so I am hoping if I destroy it on exit it will stop this from happening.
Cheers
Same! Anyone please? It should be simple enough... @triniwiz ? Or @zoocreative did you manage to find a solution?
I did actually manage to find a solution, and it fixed the crashing I was having.
In your component:
import { Page } from 'tns-core-modules/ui/page/page';
export class MarkerCardComponent implements OnInit {
vidPlayer: any;
constructor(
private _page: Page,
) {
}
ngOnInit(): void {
let that = this;
this._page.on('navigatingFrom', function() {
console.log("** Leaving Page **");
if (that.vidPlayer) {
that.vidPlayer.destroy();
}
});
}
onPlayerLoaded(args) {
this.vidPlayer = args.object;
}
}
In your view
<YoutubePlayer #videoPlayer apiKey="###" [src]="video" (loaded)="onPlayerLoaded($event)"></YoutubePlayer>
Not sure if it's the tidiest of solutions but it works :)