【发布时间】:2016-05-18 18:53:45
【问题描述】:
我在尝试在 AngularJS 中为视频设置源时遇到问题。
这是视图的 HTML 代码:
<div class="row">
<div class="col-lg-10 col-lg-offset-1">
<video width="100%" controls>
<source ng-src="{{levelContent.levelVideo}}" type="video/mp4">
<!--<source ng-src="Content\img\cortes.mp4" type="video/mp4">-->
Your browser does not support HTML5 video.
</video>
</div>
</div>
这是该视图的控制器的代码:
(function () {
'use strict';
angular
.module('iziCooker')
.controller('LevelController', LevelController);
LevelController.$inject = ['$scope', 'LevelContentService', '$routeParams', 'LevelService', '$sce' ,'$location'];
function LevelController($scope, LevelContentService, $routeParams, LevelService, $sce ,$location) {
$scope.levelId = -1;
$scope.levelContent = [];
function GetLevelContent() {
LevelContentService.SetLevelId($routeParams.levelId);
$scope.levelId = LevelContentService.GetLevelId();
LevelService.GetLevelContent($scope.levelId).then(function (data) {
$scope.levelContent = data;
LevelContentService.SetLevelName = data.name + " - " + data.description;
$scope.levelContent.levelVideo = $sce.trustAsResourceUrl(data.levelVideo);
});
}
GetLevelContent();
console.log("Level Controller Loaded!");
}
})();
我正在 IE 和 Chrome 上测试我的应用程序,第一个可以正常工作,但我最常使用的第二个没有。
在 IE 上:
在 Chrome 上:
我在 Chrome 上单独测试了视频,效果很好。我也尝试使用硬编码的 src,如您在上面看到的,它也可以工作。我认为这可能与 $sce 有关,但似乎不是。
【问题讨论】:
-
你试过直接在视频元素上设置源吗?我隐约记得遇到过这样的问题,并且 ng-src 无法处理
<source>元素。 -
我尝试直接设置源,它就像一个魅力。角度和 HTML5 的行为很奇怪。非常感谢!
标签: angularjs google-chrome html5-video src