I am developing an Android app using Cordova and Ionic framework. I am playing a YouTube video with InAppBrowser using the code below:
window.open('https://www.youtube.com/embed/rAiw2SXPS-4', '_self');
But when I press the home button on the device while playing the video, the video is not paused. Due to this issue, my app is rejected after submitting to Google Play with the reason below:
Your submission has been rejected for enabling background playing of YouTube videos in violation of the YouTube API Terms of Service. If this submission was an update to an existing app, the version published prior to this update is still available in Google Play. Please modify your app and resubmit. Additional details have been sent to your account owner's email address.
I searched for a solution but have no luck. Can anybody help?
With $ionicPlatform you can use "on" method:
It is based on Cordova pause event:
See ionic documentation here and cordova documentation here.
I was also struggling to find complete solution to pause(not stop) ongoing video(s) when device locks, but with no success. Eventually I found solution myself by combining several parts together.
Here is the directive that accomplishes YouTube player pause on device lock:
HTML for embedded YouTube player will be:
Note: above code is for ionic 2+, however for ionic 1 you can use:
Also you will need to create Angular 1 style directive instead of TypeScript one written above.
You need to set
shouldPauseOnSuspend=yes
within the options when calling theopen
method for the inappbrowser. See the documentation here: https://github.com/apache/cordova-plugin-inappbrowser.Something like this will work: