iO 中 HTML5 音频元素的持续时间值存在问题
我正在为 iOs 设备开发一个网络应用程序,但 html5 音频标签有问题...... 我设计了一个自定义音频播放器,并使用 JavaScript 函数控制歌曲。 在 safari 桌面版上,该应用程序运行良好,但在 safari 移动版上,它无法识别音频的持续时间;持续时间属性的值为 NaN。 我必须播放、停止和重播音频才能检索正确的值。 可能的原因是 safari 移动设备上禁用了媒体预加载... 有没有办法在第一次拍摄时读取正确的值?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 iOS 中的一个错误...即使在
onloadedmetadata
事件上调用的函数内部,您仍然可能会得到NaN
。就我而言,当用户选择新的 mp3 并且代码动态设置 src 属性时,这种情况会随机发生。音频播放得很好,但有时,持续时间会返回
NaN
,从而搞乱任何依赖于该值的进度指示器。This is a bug in iOS... even inside the function that gets called on the
onloadedmetadata
event, you MAY STILL getNaN
.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 returnsNaN
, screwing up any progress indicator that depends on that value.此事件触发后,元数据可用:
更多信息
https://developer.mozilla.org/en/Introducing_the_Audio_API_Extension
The medata is available after this event has fired:
More info
https://developer.mozilla.org/en/Introducing_the_Audio_API_Extension