Html 尝试将 MediaSource 对象附加为 HTML5 视频标记的源时出现“不允许加载本地资源”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17682978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:13:21  来源:igfitidea点击:

Getting "Not allowed to load local resource" error while trying to attach a MediaSource object as the source of a HTML5 video tag

javascripthtmlhtml5-videomedia-source

提问by Mathew

I am trying to get thisexample to work. It works fine when I click the link. But when I try to download the HTML file on my local machine and try the same, it is throwing this error.

我正在努力让这个例子发挥作用。当我点击链接时它工作正常。但是,当我尝试在本地计算机上下载 HTML 文件并尝试相同操作时,它会抛出此错误。

Not allowed to load local resource: blob:null/6771f68d-c4b8-49a1-8352-f2c277ddfbd4

不允许加载本地资源:blob:null/6771f68d-c4b8-49a1-8352-f2c277ddfbd4

The line of code that seems to be causing the issue is this,

似乎导致问题的代码行是这样的,

video.src = window.URL.createObjectURL(mediaSource);

video.src = window.URL.createObjectURL(mediaSource);

What this line of code is doing is basically trying to set the source of the video tag media element to the MediaSource object. I have tried various permutations without much luck.

这行代码所做的基本上是尝试将视频标签媒体元素的来源设置为 MediaSource 对象。我尝试了各种排列,但运气不佳。

I am using Chrome Version 28.0.1500.72 m, which is the latest stable release.

我使用的是 Chrome 版本 28.0.1500.72 m,这是最新的稳定版本。

I would appreciate any pointers.

我将不胜感激任何指针。

回答by Filipe Merker

As @dandavis has said, "run it from http: not file".

正如@dandavis 所说,“从 http: not file 运行它”。

I'm posting this as an answer for the sake of organization.

为了组织起见,我将此作为答案发布。

For starters: Running you project from http means having a http server (such as apache or a simple node http-server) and running your project via http://localhost.

对于初学者:从 http 运行您的项目意味着拥有一个 http 服务器(例如 apache 或一个简单的节点http-server)并通过http://localhost运行您的项目。

回答by Clinton Roy

Install http-serverglobally using npm command(provided you have installed Node.jsin your system beforehand). Navigate to your file folder in CMD and type http-server. Your app should run in localhost:8080.

使用 npm 命令全局安装http-server(前提是您事先在系统中安装了Node.js)。导航到 CMD 中的文件夹并键入http-server。您的应用程序应该在localhost:8080 中运行。