Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7932301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:58:31+00:00 2026-06-03T20:58:31+00:00

I was learning some JavaScript, to select a file and use it to create

  • 0

I was learning some JavaScript, to select a file and use it to create an objectUrl which can be set as the src of an HTML5 video. I am trying this out in Chrome version 18.0.1025.162 on Ubuntu Lucid, and using a local HTML file with a JavaScript file and media files in the same folder.

I can select a video file using the input element and when I click on a play link, the JavaScript function playVideo() is executed.

<video id="vid" name='myvid' width="640" height="360" controls="controls">
       <source src="test.webm" type="video/webm" />
</video>
<br><a href="#" id="playlnk">Play </a> </li>
<br><input type="file" name="fileselect" id="fselect"> </input>

JavaScript file is

$(document).ready(function(){
        player=$('#vid').get(0);        
        $('#playlink').click(function(){playVideo(player);});        
    });
function setVideoSrc(player,file){
    console.log('winurl='+window.URL);
    var fileURL = window.URL.createObjectURL(file);
    player.src=fileURL;
    player.load();
    return;
}
function playVideo(player) {
     var file=document.getElementById('fselect').files[0];
     console.log('you chose:'+file);
     if (file==undefined){
        console.log('no file chosen');
     }else{
        console.log('file='+file);
        setVideoSrc(player,file);
     }     
}

When I don’t select any file and click on the playlink, the default video plays and console log says no file chosen – as expected.

The error occurs when I select a video file and then click on the playlink. Then the playVideo() method calls setVideoSrc() in which the console log says window.URL' is undefined`

Why does this happen? Can someone help me correct this?
Here is the console log output

you chose:[object File] //from playVideo() function
file=[object File]   //from playVideo() function
winurl=undefined   //setVideoSrc() function
Uncaught TypeError: Cannot call method 'createObjectURL' of undefined 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:58:33+00:00Added an answer on June 3, 2026 at 8:58 pm

    Use window.webkitURL in Chrome.

    This whould work in both Chrome and FireFox

    function setVideoSrc(player,file){
        var myURL = window.URL || window.webkitURL
        console.log('winurl='+myURL);
        var fileURL = myURL.createObjectURL(file);
        player.src=fileURL;
        player.load();
        return;
    }
    

    See also:

    • http://caniuse.com/#feat=bloburls
    • https://developer.mozilla.org/en/DOM/window.URL.createObjectURL
    • http://www.w3.org/TR/FileAPI/#url
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm struggling with some XML in javascript, how can i select only tags with
I'm just beginning learning javascript and jQuery and need some help. I am trying
There is something I can't digest. I'm learning some assembler and right now I'm
I am doing some self learning about Patern Matching in Javascript. I got a
Ok I've been learning some of the more advanced aspects of Javascript and now
I started learning programming 4 months ago. So far I already know some javascript(and
I am looking for some insight on learning CoffeeScript without learning pure JavaScript. I
I'm learning more about javascript OOP by rolling my own console.log variant with some
I'm pretty new to JavaScript, which I am learning on my own. I'm currently
I'm having a tough time learning Javascript/Ext-JS. I setup the Spket plug-in for some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.