【问题标题】:Not allowed to load local resource: file:// while trying to play video尝试播放视频时不允许加载本地资源:file://
【发布时间】:2018-03-03 04:45:00
【问题描述】:

我正在使用下面的代码在本地机器上播放视频存储,但我在 chrome 中遇到错误,例如 Not allowed to load local resource: file:/// 而在 Firefox Web 浏览器中我得到视频格式或 MIME 类型不是支持。

    <video src="{{trainingVideoURL | trustAsResourceUrl}}"    width="500" height="300" style="margin-left:200px;" controls="controls" type="video/mp4">
</video>

下面是获取url的控制器

function loadPreReqs() {
        $scope.trainingVideoIdPk=$routeParams.trainingVideoIdPk;
        trainingFactory.getTrainingVideoPath($scope.trainingVideoIdPk).success(function(data) {         
            $scope.trainingVideoURL= data;
         }).error(function(error){
             alert(error.status);
         });
    }

使用 $sce 过滤以避免阻止从不安全的 URL 加载资源

.filter('trustAsResourceUrl', function ($sce) {
          return function(videoPath) {
            return $sce.trustAsResourceUrl('file://'+ videoPath);
          };

    });

我在尝试播放视频时遇到错误 不允许加载本地资源:chrome 中的 file:///home/abc/project/Training/videos/Oral%20&%20Maxillofacial%20Surgery.mp4

我尝试了其他解决方案以及这篇文章中建议的Getting "Not allowed to load local resource" error while trying to attach a MediaSource object as the source of a HTML5 video tag

但出现错误:GET http://home/abc/project/Training/videos/Oral%20&%20Maxillofacial%20Surgery.mp4 net::ERR_NAME_NOT_RESOLVED

【问题讨论】:

    标签: angularjs html video


    【解决方案1】:

    这对你来说可能是也可能不是一个有效的答案,但我听说过类似的事情,JS 无法访问 Google Chrome 中的本地资源以及这里提到的内容 -

    https://chrisbitting.com/2014/03/04/allow-local-file-access-in-chrome-windows/

    修复了该特定问题。默认情况下,Chrome 在某些情况下不允许从正在浏览的文件(本地)访问没有适当的 --allow-file-access-from-files 标志的文件系统。这意味着除非您使用该标志清理运行 chrome,否则从 Chrome 中的本地系统运行的任何文件都无法访问本地文件系统。

    这只是 Google Chrome 的一项安全功能。

    就像我说的,可能无法解决问题,但值得一试:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-23
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-08
      相关资源
      最近更新 更多