Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

createObjectURL is returning undefined in Chrome

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.

like image 951
Rupsa Avatar asked Jul 19 '11 23:07

Rupsa


People also ask

What can I use instead of createObjectURL?

Deprecation of createObjectURL and replace with the new HTMLMediaElement.

What does URL createObjectURL return?

The URL.createObjectURL() static method creates a string containing a URL representing the object given in the parameter. The URL lifetime is tied to the document in the window on which it was created. The new object URL represents the specified File object or Blob object.

What is an object URL?

Blob URL/Object URL is a pseudo protocol to allow Blob and File objects to be used as URL source for things like images, download links for binary data and so forth. For example, you can not hand an Image object raw byte-data as it would not know what to do with it.


1 Answers

I think you should use window.webkitURL.createObjectURL() as noted in https://developer.mozilla.org/en/DOM/window.URL.createObjectURL

Note: This method is prefixed in Chrome and Webkit as window.webkitURL.createObjectURL().

like image 136
NeverAgain Avatar answered Oct 23 '22 06:10

NeverAgain