HTML5 video/audio player control play & pause with AngularJS

后端 未结 2 1765
南方客
南方客 2021-01-03 07:53

I want to control HTML5 audio/video player with AngularJS. I want to play & pause that player. I can do this using jQuery. But I need it to work with AngularJS.

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-03 08:33

    • https://github.com/2fdevs/videogular
    • creating your own custom directive can does the job for you (Preferred and reusable),

      The simplest way is using angular.element and selecting the required video element from the DOM using its functionalities.

       
      

      //controller

      function myCtrl($scope) {
         $scope.url = "url of video or audio"
         $scope.pauseOrPlay = function(ele){
           var video = angular.element(ele.srcElement);
           video[0].pause(); // video.play()
         }
      }
      

    more about angular.element https://docs.angularjs.org/api/ng/function/angular.element

提交回复
热议问题