stop other video that is playing in background on play the new one

后端 未结 2 579
渐次进展
渐次进展 2020-12-07 04:54

I am using Videogular to show video. could you please help me how to stop/pause other video when user click on play button to new one. So by this at a time user can play onl

2条回答
  •  有刺的猬
    2020-12-07 05:18

    While the answer from elecash is a fine answer, there is a lot of guessing and storage. I choose to store only the active api on the $rootScope and paused the other player when a new player has started.

    
    
    
    controller('VideoPlayerCtrl', ['$rootScope','$scope', function($rootScope,$scope) {
      $scope.playerReady = function(api) {
        $scope.api = api;
      };
    
      $scope.stateChange = function(state) {
        if(state=='play') {
          if($rootScope.playingVideo && $rootScope.playingVideo != $scope.api) $rootScope.playingVideo.pause();
          $rootScope.playingVideo = $scope.api;
        }
      };
    }]);
    

提交回复
热议问题