MOBILE-2477 core: Pause Youtube videos in Android when screen is locked
parent
60c5ff9bc5
commit
3f0bcd95a4
|
@ -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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue