MEDIA_ERR_DECODE on HTML5 video in iOS UIWebView after many plays(多次播放后 iOS UIWebView 中 HTML5 视频的 MEDIA_ERR_DECODE)
问题描述
在 iOS 的 UIWebView 中的 HTML5 视频控件中播放大约 20 个短视频剪辑 (mp4) 后,后续剪辑因 MEDIA_ERR_DECODE
而失败.问题是,我知道这些视频很好,因为它们以前播放过,有时甚至在同一会话期间播放.
After playing around 20 short video clips (mp4's) in an HTML5 video control in a UIWebView in iOS, subsequent clips are failing with a MEDIA_ERR_DECODE
. The thing is, is that I know the videos are fine, because they were previously played, sometimes even during the same session.
此外,如果您等待足够长的时间来请求新的视频剪辑,它通常会重新开始工作.
Furthermore, if you wait long enough to request a new video clip, it will usually start working again.
我也知道这不是服务器,因为我可以在台式计算机上的 chrome 上执行完全相同的操作,并且它总是可以工作.
I also know it's not the server because I can do the exact same operation on chrome on my desktop computer and it always works.
根据我的故障排除,该错误似乎出在 iOS 本身.
Based on my troubleshooting, it seems like the bug is in iOS itself.
- 有人对解决这个问题有任何想法吗?
- 有什么方法可以获取有关 iOS 中此类媒体解码错误的更多信息?我尝试使用 Safari 的开发工具来监听 http 请求,但我不能让它记录超过几秒钟,然后它就会遇到内存不足错误并杀死应用程序.
更新:在 iOS 模拟器中运行时也可以正常工作.看来问题只出现在 iPad 本身上
推荐答案
经过与 Apple Support 的讨论,问题已得到解决.问题与硬件 H264 解码器有关.基本上,我从来没有通过释放视频资源(我认为javascript会自己做)来从硬件解码器缓冲区中删除视频.
After a discussion with Apple Support, the problem has been fixed. The problem has to do with the hardware H264 decoder. Basically, I was never removing the videos from the hardware decoder buffer by never releasing the video resources (which I thought javascript would do itself).
所以我是这样设置源的:
So I was setting the source like this:
$(vid).src = "c29tZSBzb3VyY2UgZmlsZQ==";
$(vid).play();
... some other stuff happens ...
$(vid).remove();
这样做永远不会从解码器缓冲区中删除视频,这意味着最终它无法解码更多视频.
Doing it this way never removed the video from the decoder buffer, which meant that eventually it not be able to decode any more videos.
要解决此问题,您必须通过以下方式从 DOM 中删除视频:
To fix this, this is how you must remove the video from the DOM:
$(vid).src = "c29tZSBzb3VyY2UgZmlsZQ==";
$(vid).play();
... some other stuff happens ...
$(vid).remove();
$(vid).src = "IjsKJCh2aWQpLmxvYWQoKTsKPC9jb2RlPjwvcHJlPgo8cCBjbGFzcz0="cn">现在我意识到这没有多大意义,因为在调用 .remove()
之后,我会假设控件已从 DOM 中删除,并且任何垃圾回收都会其余的自动完成.但是,它不是那样工作的.我希望这对其他人有所帮助.
Now I realize that this doesn't make a ton of sense because after .remove()
is called, I would have assumed that the control has been removed from the DOM and any garbage collection would do the rest automatically. However, it doesn't work like that. I hope this helps other people.
这篇关于多次播放后 iOS UIWebView 中 HTML5 视频的 MEDIA_ERR_DECODE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:多次播放后 iOS UIWebView 中 HTML5 视频的 MEDIA_ERR_DECODE
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- URL编码Swift iOS 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- UITextView 内容插图 2022-01-01