MOBILE-2477 core: Pause Youtube videos in Android when screen is locked

main
Albert Gasset 2018-07-11 12:16:17 +02:00
parent 60c5ff9bc5
commit 3f0bcd95a4
1 changed files with 24 additions and 0 deletions

View File

@ -141,5 +141,29 @@ export class MoodleMobileApp implements OnInit {
loadCustomStrings(); loadCustomStrings();
} }
}); });
// Pause Youtube videos in Android when app is put in background or screen is locked.
this.platform.pause.subscribe(() => {
if (!this.platform.is('android')) {
return;
}
const pauseVideos = (window: Window): void => {
// Search videos in iframes recursively.
for (let i = 0; i < window.length; i++) {
pauseVideos(window[i]);
}
if (window.location.hostname.match(/^www\.youtube(-nocookie)?\.com$/)) {
// Embedded Youtube video, pause it.
const videos = window.document.querySelectorAll('video');
for (let i = 0; i < videos.length; i++) {
videos[i].pause();
}
}
};
pauseVideos(window);
});
} }
} }