简体   繁体   English

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

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

I am trying to get this example 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);

What this line of code is doing is basically trying to set the source of the video tag media element to the MediaSource object.这行代码所做的基本上是尝试将视频标签媒体元素的来源设置为 MediaSource 对象。 I have tried various permutations without much luck.我尝试了各种排列,但运气不佳。

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.我会很感激任何指示。

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 运行您的项目。

Install http-server globally using npm command(provided you have installed Node.js in your system beforehand).使用 npm 命令全局安装http-server (前提是您事先在系统中安装了Node.js )。 Navigate to your file folder in CMD and type http-server .在 CMD 中导航到您的文件夹并输入http-server Your app should run in localhost:8080 .您的应用程序应该在localhost:8080中运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM