Prevent idle state when uploading (web app on iOS)

两盒软妹~` 提交于 2019-12-02 10:08:13

Originally I couldn't find an answer to this (most likely due to my particular phrasing of the question), but I ended up adding the following to my upload modal which prevented my phone from sleeping while the modal was open (only tested on iOS7):

<div style="display:none">
   <audio id="prevent_sleep" style="display:none" src="prevent_sleep.mp3" onended="this.play();" controls loop autobuffer autoplay></audio>
</div>
//prevent_sleep.mp3 is a 10 second silent mp3 file

<script>
   window.onload = function() {
      var audioEl = document.getElementById("prevent_sleep");

      audioEl.load();
      audioEl.play();
   };
</script>

Which I found at http://flax.ie/how-to-get-hidden-autoplaying-audio-in-html5-on-ios/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!