在我的应用中,我使用视频流。我从我的API和angularjs app中的视频标签显示流中调用此流。
<video id="video" class="iframePreview" controls="true" autoplay
type="application/x-mpegURL">
</video>
<button class="button_pv btn btn-default"
ui-sref="camera({'streamID': monitorsIds[0] })">
Recorded Events
</button>
在ctrl中,我从API获取网址并传递给<video></video
return $http
.get(serviceBase + "aaaaaa" + Id)
.then(function(response) {
$rootScope.monitorsIds = [];
angular.forEach(response.data, function(key, value) {
$rootScope.monitorsIds.push(key.monitor);
});
if(Hls.isSupported()) {
var video = document.getElementById('video');
var hls = new Hls();
hls.loadSource(window.monitorsIdsStreamWin[0]);
hls.attachMedia(video);
}
});
一切都运行良好,但是当我在网络控制台中更改状态时,我仍然看到加载流数据......
如何破坏这个? 日Thnx
答案 0 :(得分:1)
这是一个通用指令:
app.directive("hlsSource", function() {
return {
link: postLink,
};
function postLink(scope, elem, attrs) {
var hls;
var video = elem[0];
scope.$watch(attrs.hlsSource, function(value) {
if (!value) return;
//else
hls && hls.destroy();
hls = new Hls();
hls.loadSource(value);
hls.attachMedia(video);
scope.$eval(attrs.onAttach({$hls: hls, $video: video});
});
scope.$onDestroy(function() {
hls && hls.destroy();
});
}
});
用法:
<video id="video" class="iframePreview" controls="true" autoplay
type="application/x-mpegURL"
hls-source="$ctrl.source" on-attach="$ctrl.onAttach($hls,$video)">
</video>
JS
app.controller("videoController", function() {
var current_hls;
var current_video;
this.onAttach = function(hls, video) {
current_hls = hls;
current_video = video;
hls.on(Hls.Events.MANIFEST_PARSED,function() {
current_video.play();
});
};
this.$onDestroy = function() {
current_hls && current_hls.destroy();
};
this.source = 'https://video-dev.github.io/streams/x36xhzz/x36xhzz.m3u8';
})