'How to fix "Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.."

I am getting that error message when I try to retrieve and play a video file(blob),stored in indexedDB.I basically open a transaction to the db,get the file and then assign the source object to the HTML video element.

Basically I managed to store the videos in indexedDB,all i want to do now is retrieve and play the video files in the browser. I get that error message.I did some reading and found out it could be due to the deprecation of "createObjectURL" but I am not sure as to how to incooperate the new approach into my code.

 <script type="text/javascript"> 

      (function () {

        if (!('indexedDB' in window)) {
  console.log('This browser doesn\'t support IndexedDB');
  return;
}
    // IndexedDB
    window.indexedDB = window.indexedDB || window.webkitIndexedDB || 
                       window.mozIndexedDB || window.OIndexedDB || 
                       window.msIndexedDB,
    IDBTransaction = window.IDBTransaction || 
                     window.webkitIDBTransaction ||
                     window.OIDBTransaction || window.msIDBTransaction,
    dbVersion = 1.0;
 
    var indexedDB = window.indexedDB;
 
    // Create/open database
    var request = indexedDB.open("Syafunda_Videos");
     
    request.onerror = function (event) {
        // Failed to Open the indexedDB database
    };
 
    request.onsuccess = function (event) {
        db = request.result;
         
        // Open a transaction to the database
        var transaction = db.transaction(["Videos"], "readwrite");
 
        //Retrieve the video file
        transaction.objectStore("Videos").get("1").onsuccess = function (event) {        
        var videoFile = event.target.result;
        var URL = window.URL || window.webkitURL;
        var videoURL = URL.createObjectURL(videoFile) ;
                       
         // Set video src to ObjectURL        
        var videoElement = document.getElementById("video");
            videoElement.setAttribute("src", videoURL);
 
        var mimeDisplayElement = document.getElementById("vidMimeDisplay");
            mimeDisplayElement.innerHTML = videoFile.type;
        };
    }
})();

</script>


Solution 1:[1]

The problem most likely has to do with what videoFile is.

URL.createObjectURL needs a Blob object to generate a URL for you, but most likely videoFile is a regular JavaScript object, where the video in question is a property on that object.

Probably you've got something like

videoFile = {
    [primaryKey]: "1",
    yourVideo: Blob(...)
};

How is your document stored? You might need to further pull your video file off the event.target.result object.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ryan Dabler