MediaElement.js setSrc 不适用于 FF、IE7-8 上的 Flash 回退
我看过一些关于这个问题的讨论,但没有真正的答案。我已经成功地让 mediaelement.js
为我工作,只是它根本不允许我 setSrc()
进行 Flash 回退。经过这么多工作之后,这真是一个巨大的遗憾。
对于一些背景知识,我使用 mediaelement-and-player.js
v2.1.9 并使用他们的播放器 API 通过 player.setSrc
更改媒体 src。我正在播放音频 MP3。
我在 FF Mac 中收到此错误:
this.media.setSrc 不是一个函数
并且在 IE8 Win 中出现此错误:
SCRIPT445:对象不支持此操作
我发现很难相信这没有经过充分测试,因为它似乎是其 API 的基础部分。我见过一些有关类似问题的其他问题,但同样没有真正的答案。
I've seen a few discussions about this, but no real answers. I've had a lot of success getting mediaelement.js
working for me except that it simply will not let me setSrc()
on flash fallbacks. This is a huge bummer after so much work.
For a little background I'm using mediaelement-and-player.js
v2.1.9 and using their player's API to change the media src via player.setSrc
. I'm playing audio MP3s.
I'm getting this error in FF Mac:
this.media.setSrc is not a function
And this error in IE8 Win:
SCRIPT445: Object doesn't support this action
I find it hard to believe that this wasn't fully tested given that it seems a base part of their API. I've seen some other issues about similar problems but again, no real answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要将“flashmediaelement.swf”添加到您的代码中。
You would need to add "flashmediaelement.swf" to your code.
有同样的问题。通过添加非空
src
和type="audio/mp3"
属性解决了这个问题:这里建议使用
preload="none"
,因为如果没有它,该元素将向当前页面的 URL 发送额外的请求以尝试下载音频。更新:找到了另一种方法,可以将零长度的WAV文件嵌入到
src
中,这样您就可以正常使用preload
属性而不必担心如果用户在设置正常src
之前单击播放按钮,将会发送不需要的请求。不用担心
type
和src
不兼容,因为根据 音频元素规范,type
不是audio 根本没有标签(
type
只是source
标记的属性),此处放置它只是为了修复 MediaElement.js 行为。Had the same problem. Solved it by adding non-empty
src
andtype="audio/mp3"
attributes:Presence of
preload="none"
is recommended here, because without it the element will send an additional request to a current page's URL in an attempt to download the audio.Update: found an alternative way, zero-length WAV file can be embedded in
src
, thus you may usepreload
attribute normally and stop worrying about that an unneeded request will be sent if a user will click the play button before you set normalsrc
.Don't worry about
type
andsrc
incompatibility, because, according to audio element specification,type
isn't legal attribute ofaudio
tag at all (type
is only asource
tag's attribute), here it's placed only to fix MediaElement.js behavior.我在 github 上回答了类似的问题。这是我的解决方案:
当初始化 mediaElement 播放器后过早调用 setSrc 方法时,就会发生这种情况。由于 flash 回退,swf(及其 api 方法)在成功事件触发之前将不可用。之后 setSrc 在 IE8 中工作正常。
我不想在成功处理程序中设置初始源。因此,我使用布尔变量来检查成功事件是否发生。在我的源设置方法中,每当布尔变量等于 false 时,我都会检查其值并使用递归性(使用 setTimeout 来防止过度杀伤)。这对我有用。
I answered a similar question on github. Here's my solution:
This occurs when the setSrc method is called too soon after initializing the mediaElement player. Due to the flash fallback the swf (and therefore its api methods) will not be available until the success event is fired. After that setSrc works fine in IE8..
I didn't want to set the initial source from within the success handler. Therefore I used a boolean var to check whether the success event had occurred. In my source setting method I check for its value and use recursiveness (with a setTimeout to prevent overkill) whenever the boolean var equals false.. Did the trick for me.