当第二个播放器开始播放时,如何阻止音频播放器暂停?

时间:2017-06-04 21:58:46

标签: javascript angularjs soundcloud

我正在使用AngularJS构建一个应用程序,我正在使用soundcloud API通过两个不同的播放器传输声音。

我的问题是我希望两个玩家同时播放声音,而这一点目前还没有发生。

angular
.module('mtcApp')
.controller('PlayerCtrl', PlayerCtrl);

PlayerCtrl.$inject = ['$scope'];
function PlayerCtrl($scope){

  $scope.startPlayerA = function(track){
    const id = track.id;
    console.log(id);
    SC
      .stream(`/tracks/${id}`)
      .then(function(player){
        $('#playA').on('click', function(){
          player.play();
          
        });
        $('#pauseA').on('click', function(){
          player.pause();
          console.log(player);
        });
      });
  };

  $scope.startPlayerB = function(track){
    const id = track.id;
    console.log(id);
    SC
      .stream(`/tracks/${id}`)
      .then(function(player){
        $('#playB').on('click', function(){
          player.play();
        });
        $('#pauseB').on('click', function(){
          player.pause();
        });
      });
  };
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="" ng-controller="MainCtrl">
  <div class="">
    <div class="">
      <div ng-controller="PlayerCtrl as vm">


        <div class="fl w-50 mv3 bg-grey">
          <h3>Deck A</h3>
          <button id="playA"> **PLAY** </button>
          <button id="pauseA">**STOP**</button>
        </div>
        <div class="fl w-50 mv3 bg-grey">
          <h3>Deck B</h3>
          <button id="playB"> **PLAY** </button>
          <button id="pauseB">**STOP**</button>
        </div>
        
        <sc-search></sc-search>

    </div>
    </div>
  </div>
</div>

现在发生的事情是,如果$ scope.startPlayerA.player正在播放并且点击$(#playB),$ scope.startPlayerB.player开始播放但$ scope.startPlayerA.player停止,任何人都知道如何我可以防止这种情况发生吗?

感谢

0 个答案:

没有答案