HTML
<li>
<a ng-href ng-click="startStreaming(camera);">{{camera.name}}<i class="fa fa-tv"></i></a>
</li>
<object events="True" id="vlc" codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab"
classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921">
<embed width="800" height="650" loop="no" autoplay="yes" version="VideoLAN.VLCPlugin.2"
type="application/x-google-vlc-plugin" id="vlc" embed-src="" src="">
</object>
控制
cameraModule.controller('streamingCtrl', ['$scope', '$rootScope', 'cameraModuleServiceAPI', '$timeout', 'svc', '$q', 'sharedService','mySharedService',
function ($scope, $rootScope, cameraModuleServiceAPI, $timeout, svc, $q, sharedService, mySharedService) {
var rtspobj = null;
$scope.startStreaming = function (data) {
// Request Start Streaming
var jason_start_streme = { "START_STREAMER_REQUEST": { "command ": 1, "cameraID": 123, "streamingMedium": 0 } };
cameraModuleServiceAPI.start_streme(jason_start_streme).then(function (data) {
$rootScope.$watch(svc.getMessage, function (v) {
$timeout(function () {
if (v != '') {
rtspobj = angular.fromJson(v.content);
$rootScope.cameraRTSPUrl = rtspobj.START_STREAMER_RESPONSE.RtspURL;
console.log("Camera Click : " + $rootScope.cameraRTSPUrl);
sharedService.prepForBroadcast($rootScope.cameraRTSPUrl);
$scope.$apply();
}
});
});
};
指令
myApp.directive('embedSrc', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var current = element;
scope.$watch(attrs.embedSrc, function () {
var clone = element.clone().attr('src', scope.cameraRTSPUrl);
current.replaceWith(clone);
current = clone;
});
}
};
});
要求:
当调用函数startStreaming
时,将在控制器中获取视频URL,然后只调用指令将更改
embed
src并播放视频。
如何在点击startStreaming时调用我的指令,将视频网址从控制器传递到指令并最终更改embed src?