nativescript-youtubeplayer icon indicating copy to clipboard operation
nativescript-youtubeplayer copied to clipboard

How can I destroy the player in Angular?

Open zoocreative opened this issue 6 years ago • 2 comments

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

zoocreative avatar Nov 08 '19 17:11 zoocreative

Same! Anyone please? It should be simple enough... @triniwiz ? Or @zoocreative did you manage to find a solution?

imperatormk avatar Jan 14 '20 20:01 imperatormk

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 :)

zoocreative avatar Jan 15 '20 10:01 zoocreative