I'm trying to make accessible a flowplayer media player using a directive. so that parent controllers can broadcast events and then the player just responds to those events using listeners. the events are working but the player is undefined so not really working. my problems are: 1) player not initializing. - i must not be setting this up correctly. 2) I want the player object available in the scope as $scope.player so I can tell it to $scope.player.play() or $scope.player.stop(). something is missing in my understanding of controller, vs link as well as initialization of the player when the DOM is ready as I'm not able to assign the player to a scope variable to start/stop it. I'm able to init the player using jquery from the console, so it seems my init function is just not running at the right time?
code
//view
<div ng-Controller="AudioCtrl">
<div url="pathto.mp3" audio-flowplayer><div>
</div>
//controller
App = angular.module("myapp", [])
App.controller 'AudioCtrl', ['$scope', ($scope) ->
$scope.togglePlay() =->
$scope.broadcast('start')
//directive
App.directive 'audioFlowPlayer' ->
restrict: 'A'
scope: {
url: '@'
}
template: '<a href="{{url}}"</a>'
controller: ($scope, $element, $attrs) ->
$scope.init_player = ->
$scope.player =
$element.flowplayer("/path/to/flow.swf",
clip:
audoPlay: false
)
$scope.$on "start", ->
$scope.player.play()
link: (scope, element, attrs) ->
scope.init_player()
]