Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding onPause/onResume to a Youtube video within an Ionic 2 page

I have a small issue I need fixing on a very basic demo Android app in Ionic 2.

When a Youtube video plays on the Homepage, if you press the power button or the phone goes into sleep/lock mode the Youtube video continues playing. This issue causes Google to reject the app in the Play Store as they do not allow this to happen on Youtube embeds.

So I need to add some code to pause the video if the state changes and resume when it wakes up again.

The feature I need to add seems to be called onPause and onResume but I am unsure how and where to add the code to get this feature working with this custom Youtube code.

Here are the files in a repo, and APK (only 3mb) just a change to the homepage on a blank ionic 2 install, where you can see the issue in action.

Github Repo
APK in Github

like image 471
me9867 Avatar asked Mar 10 '23 19:03

me9867


1 Answers

I would add a comment to add to what n00b said, but I don't have 50 reputation points yet. To add to noobs answer and give an extra hint. Please mark n00b as the correct answer as he posted first.

import { DomSanitizer, SafeResourceUrl} from '@angular/platform-browser';

export class page {
    currentVideoSource: SafeResourceUrl;
    constructor(public navCtrl: NavController, private sanitizer: DomSanitizer) {
        this.currentVideoSource = this.sanitizer.bypassSecurityTrustResourceUrl("youtubeurl");
    }

now src should work with something like the following in the iframe

[src]="currentVideoSource";
like image 50
Strange Graphs Avatar answered Apr 26 '23 01:04

Strange Graphs