0

I have list of video files(links) stored in internal server. I need to play those video files using JavaScript and HTML. This is my code

<video width="600" id="playVideoPath" controls autoplay></video>

$scope.playVideoFile = function (row) {
    var video = document.getElementById('playVideoPath');
    var source = document.createElement('source');
    source.setAttribute('src', row.filePath);
    video.appendChild(source);
    video.play();
}

but browser displays following error when i try to play file enter image description here

Saranga
  • 530
  • 2
  • 8
  • 29

1 Answers1

1

As the error states, your browser is not allowed to access local resources (this would be a huge security risk! Just think if a website could read any file it wanted to).

You'll either need to upload and store the file on your server, or host the video file with a utility like static-server. With static server, you just need to install, run static-server -p 3000 (you can use almost any port you want) where your video file is (System Videos in this case), and then you can access it via http://localhost:3000/myVideo.mp4.

Greg Rozmarynowycz
  • 2,037
  • 17
  • 20
  • The browser is allowed to access local resources when launched with the appropriate flags. – guest271314 Jan 15 '18 at 07:07
  • I chose to exclude this because it's clunky, still a security risk, and an it's outside the scope of a programmatic (or widely applicable) fix. Using a static serve utility is an all around much better option. – Greg Rozmarynowycz Jan 15 '18 at 07:24
  • What do you mean by "clunky"? What are the security risks? Commented due to "not allowed" portion of Answer. The functionality is possible. – guest271314 Jan 15 '18 at 07:27
  • You have to find the Chrome executable in your system (not necessarily very easy) and you're literally exposing your entire local file system to the internet. It's dangerous. It's easier (and very much safer) to run a few npm commands. – Greg Rozmarynowycz Jan 15 '18 at 07:31
  • You do not have to "find the Chrome executable" you merely need to create a new launcher (using the command at the current launcher, or icon) or launch the instance of Chrome from the command line with the flag set and `--user-data-dir` set. You have not provided details of what you mean by "dangerous"? How would the entire local file system be exposed to the internet? _"It's easier (and very much safer) to run a few npm commands."_ . Is `npm` "safer" https://blog.risingstack.com/controlling-node-js-security-risk-npm-dependencies/? – guest271314 Jan 15 '18 at 07:33
  • can you help me to create internal server to host video file using IIS. I have created FTP, But it not helps for my matter. – Saranga Jan 16 '18 at 03:44