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
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";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With