【发布时间】: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
【问题讨论】: