createObjectURL 在 Chrome 中返回未定义
尝试使用 createObjectDataURL 更改视频源文件。它在 Firefox 中工作正常,但在 Chrome(版本 12.0.742.122 m)中无法工作。代码不会引发任何错误,但会为 createObjectDataURL 返回 undefined。我尝试了所有的可能性,但它总是返回未定义。
<!DOCTYPE html>
<html>
<head>
<title>Check CreateObjectURL</title>
</head>
<script type="text/javascript" language="javascript">
window.URL = window.URL || window.webkitURL;
function ChangeProperty()
{
var v = document.getElementById("myvideo");
var file = document.getElementById("fileControl").files[0];
v.setAttribute("src",window.URL.createObjectURL(file));
}
</script>
<body>
<div >
<video id="myvideo" src="movie.ogg" controls ></video>
<input type="file" id="fileControl" />
<button id="btnprops" onClick="ChangeProperty()" >update</button>
</div>
</body>
</html>
请帮我。已经花了很多时间了。 提前致谢。
Trying to change video source file using createObjectDataURL. It is working fine with Firefox but not working in Chrome (version 12.0.742.122 m). code is not throwing any error but returns undefined for createObjectDataURL. I tried all the possibilities but it always returns undefined.
<!DOCTYPE html>
<html>
<head>
<title>Check CreateObjectURL</title>
</head>
<script type="text/javascript" language="javascript">
window.URL = window.URL || window.webkitURL;
function ChangeProperty()
{
var v = document.getElementById("myvideo");
var file = document.getElementById("fileControl").files[0];
v.setAttribute("src",window.URL.createObjectURL(file));
}
</script>
<body>
<div >
<video id="myvideo" src="movie.ogg" controls ></video>
<input type="file" id="fileControl" />
<button id="btnprops" onClick="ChangeProperty()" >update</button>
</div>
</body>
</html>
Please help me. It has already taken lot of time.
Thanks in Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您陷入此困境,
请使用上面的代码。将 srcObject 设置为您的流。
If you get stuck in this
Use teh code above. Set the srcObject to your stream.
当我在 Chrome 中将页面作为本地文件打开时,我遇到了同样的问题。我必须使用 Apache 并通过 localhost 打开它。
I had the same problem, when I was opening the page as a local file in Chrome. I had to use Apache and open it through localhost.
这似乎是 Chromium 中的一个错误,尽管我不清楚该错误的状态:http://code.google.com/p/chromium/issues/detail?id=91136
在那里交叉发表我的评论:
编辑:刚刚发现这个类似的错误报告(FileReader API 不适用于本地内容):http://code.google.com/p/chromium/issues/detail?id=60889 这被标记为
不会修复
,原因似乎适用于所讨论的错误这里。This seems to be a bug in Chromium, though the status of the bug is unclear to me: http://code.google.com/p/chromium/issues/detail?id=91136
Crossposting my comment there:
Edit: Just found this similar bug report (FileReader API not working for local content): http://code.google.com/p/chromium/issues/detail?id=60889 This is marked
won't fix
for a reason that appears applicable to the bug discussed here.我认为你应该使用 window.webkitURL.createObjectURL() 如所述
https://developer.mozilla.org/en/DOM/window.URL.createObjectURL
I think you should use window.webkitURL.createObjectURL() as noted in
https://developer.mozilla.org/en/DOM/window.URL.createObjectURL