Problem with duration value of HTML5 audio element in iOs

荒凉一梦 提交于 2019-12-30 18:46:06

问题


I'm developing a web app for iOs device, but I have a problem with the html5 audio tag... I designed a custom audio player, and I control the song with javascript functions. With safari desktop the app works well, but on safari mobile it doesn't recognize the duration of the audio; the value of the duration property is NaN. I have to play, stop and replay the audio for retrieve the correct value. Probably the cause is that the media preload is disabled on safari mobile... Is there a way to read the correct value at the first shot?


回答1:


The medata is available after this event has fired:

 loadedmetadata

More info

https://developer.mozilla.org/en/Introducing_the_Audio_API_Extension




回答2:


This is a bug in iOS... even inside the function that gets called on the onloadedmetadata event, you MAY STILL get NaN.

In my case, this happens at random when the user selects a new mp3 and the code dynamically sets the src property. The audio plays fine, yet SOMETIMES, the duration returns NaN, screwing up any progress indicator that depends on that value.



来源:https://stackoverflow.com/questions/7246172/problem-with-duration-value-of-html5-audio-element-in-ios

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