2013-12-16 2 views
3

지시어를 사용하여 플로우 플레이어 미디어 플레이어에 액세스 가능하게하려고합니다. 상위 컨트롤러가 이벤트를 브로드 캐스팅 할 수 있고 플레이어는 리스너를 사용하여 이벤트에 응답합니다. 이벤트는 작동하지만 플레이어는 정의되지 않으므로 실제로 작동하지 않습니다. 내 문제는 : 1) 플레이어가 초기화되지 않았습니다. - 이걸 제대로 설정하면 안돼. 2) $ scope.player와 같은 스코프에서 플레이어 개체를 사용할 수있게하려면 $ scope.player.play() 또는 $ scope.player.stop()으로 말할 수 있습니다. 콘트롤러에 대한 나의 이해와, 플레이어가 DOM을 준비 할 때 링크를 초기화 할 때, 플레이어를 시작/중지시키는 스코프 변수에 할당 할 수 없기 때문에 무언가가 빠져있다. 콘솔에서 jquery를 사용하여 플레이어를 초기화 할 수 있으므로 init 함수가 적시에 실행되지 않는 것 같습니다.지시어의 미디어 플레이어 객체

코드

//view 
<div ng-Controller="AudioCtrl"> 
     <div url="pathto.mp3" audio-flowplayer><div> 
</div> 

// 컨트롤러

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() 

]

답변

1

체크 아웃이 MediaPlayer를 지시. 그것은 flowplayer, mediaelement 및 순수 html5와 함께 작동합니다. 그것은 다른 플레이어 라이브러리에서도 작동 할 수 있지만, 지금까지 테스트 한 것은 이것뿐입니다.

http://angulardirectives.joshkurz.net/dist/#/flowplayer

모든 것이 템플릿을 기반으로, 그래서 사이트에있는 있으며, Flowplayer 데모의 단지 적절한 HTML5 비디오 템플릿을 생성하여 생성 할 수 있습니다.

이 있으며, Flowplayer를 호출하는 HTML입니다

<div media-player media-type="{{mediaType}}" video-config="activeVideo" template-url="{{currentFlowplayer}}"></div> 

{{의 MediaType}} "있으며, Flowplayer"또는 어떤 기능이 요소에 전화를 걸 동일합니다. 따라서 미디어 요소 플레이어를 만들고 싶다면 media-type = "mediaelementplayer"를 설정하면됩니다. 템플릿 URL은 렌더링하려는 템플릿을 가리키며, 이것이 재생 목록 등을 만듭니다. 여기

은 지향성 링크 가능한 있으며, Flowplayer 템플릿 여기

<div class="flowplayer"> 
<video> 
    <source type="video/mp4" src="http://stream.flowplayer.org/download/640x240.mp4"> 
    <source type="video/webm" src="http://stream.flowplayer.org/download/640x240.webm"> 
    <source type="video/ogg" src="http://stream.flowplayer.org/download/640x240.ogv"> 
</video> 

<div class="fp-playlist"> 
    <a class="is-advert" href="http://stream.flowplayer.org/download/640x240.mp4"></a> 
    <a ng-repeat="video in videoConfig.playlist" href="{{video}}.mp4">Video {{$index + 1}} </a> 
</div> 

<div class="preroll-cover">pre-roll</div> 
</div> 

이다 https://github.com/joshkurz/Black-Belt-AngularJS-Directives/tree/master/directives/mediaPlayer