Continuous HTML5 audio/video playback in iOS?

我的梦境 提交于 2019-12-07 09:22:45

问题


I'm working on a mobile web app and want to allow for continuous playback of HTML5 audio or video in both Android and iOS (i.e. queue up a playlist of YouTube videos or Grooveshark songs and have them all play in a row automatically).

Android doesn't seem to be an issue, but everything I've read has suggested that Safari prevents audio from playing unless it's initiated by a user, and prevents continuous play if the screen becomes locked.

That said, Grooveshark's mobile web app will play an entire playlist of songs in my iPhone 5 (iOS 7). It'll play the next song even if I'm in another Safari tab or I lock the screen.

So the question: How do they do that?


回答1:


This code (jQuery) works for me in iPhone Safari iOS7 for continuous playback. Even if I have my screen locked/other tab it changes track when the first has ended (given a bit of patience for the new track to load)

<audio id="audio1" src="song1.mp3" controls></audio>
<script type="text/javascript">
$('#audio1').on('ended',function(){
    $(this).attr('src','song2.mp3');
    $(this)[0].play();
    });
</script>

I've read has suggested that Safari prevents audio from playing unless it's initiated by a user.

=> That is true and is by design - no work around known as of today (well ... I have seen ugly attempt to make it work).



来源:https://stackoverflow.com/questions/23281784/continuous-html5-audio-video-playback-in-ios

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