Limitations of HTML5 Audio on iOS 4? Playlisting, background, etc

心不动则不痛 提交于 2019-12-10 19:13:00

问题


I've been evaluating HTML5 audio on iOS 4 and have been trying to understand its limitations. From what I can tell...

  • It is possible to play audio in the background
  • It is not possible to fire JavaScript events in the background upon track completion
  • It is possible to fire JavaScript events while the screen is off, but Safari must be in the foreground (before turning the screen off)

My goal for this current project is to create a dynamic playlist that will continue to fire events and move to the next track even while Safari is not in the foreground. Is this possible with the current way HTML5 audio works on iOS?

I am curious about how the chaining of JavaScript events works on iOS if anyone has additional information. It seems that you are allowed to queue back to back sounds, but it must happen shortly after a "human" function happens (for example, tapping an element). Anything else that tries to queue a sound outside of this human function is denied the ability to play.

Also...

Is it even possible to have events that fire to move a real iOS application to the next track? It seems as if the application is only allowed to finish its current audio stream and then it goes into an idle state. Just trying to figure out all the angles here!


回答1:


This is quite an old question, so I'm not sure if you've found an answer already or not.


One thing I know is that an audio clip cannot be played via JavaScript on mobile Safari.

Autoplay audio files on an iPad with HTML5

The only way to make audio play, is through a click event. This wasn't the case on 3.x, but on 4.x it is. This is because Apple doesn't want the webapp to download audio on a 3g connection programmatically, so they force the user to initiate it.

I would think that if all of the tracks were started downloading (cached), then it may be possible. I would try forcing the user to start one track, and at the same time call .load() on all of the other tracks (in the same click handler). This will force the iOS device to start downloading the audio tracks, and you may be able to play the next track (not sure though).



来源:https://stackoverflow.com/questions/5054848/limitations-of-html5-audio-on-ios-4-playlisting-background-etc

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