javascript - Angular SC.get 中的 Soundcloud API 不暂停

标签 javascript angularjs api

我的 soundcloud Angular 应用程序将播放音乐,但不会暂停。这是代码。

  $scope.stream = function() {
    console.log('something');
    SC.stream('/tracks/329').then(function(player) {
      if ($scope.playing === true) {
        player.pause();
        $scope.playing = false;
        console.log("pause");
      } else {
        player.play();
        $scope.playing = true;
        console.log("play");
      }
      console.log($scope.playing + ' currently');
    });

其他解决方案不是很干燥,而是利用 ng-show 和 ng-hide 将其分为两个函数。我想我可以这样做,但我很困惑为什么这不起作用,尽管 $scope.playing 确实在 true 和 false 之间切换。

谁能告诉我我错过了什么?

最佳答案

上面的代码让玩家玩真假。

试试这个

$scope.playing = true; // for initial play 

$scope.stream = function() {
console.log('something');
SC.stream('/tracks/329').then(function(player) {
  if ($scope.playing === true) {
    player.pause();
    console.log("pause");
  } else {
    player.play();
    console.log("play");
  }
  console.log($scope.playing + ' currently');
});
//make some click event that handle player state
$scope.onClick = function(){
   $scope.playing = !$scope.playing;
}

关于javascript - Angular SC.get 中的 Soundcloud API 不暂停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34603827/

相关文章:

javascript - NodeJS - 循环内的延迟函数

php - 从网站复制文本,附加复制文本的链接?

javascript - Angular : Nested Directives and Scope Inheritance

api - IE10 中的 Angular js 204 响应阻塞

javascript - 为什么这段代码这么慢?

javascript - 未捕获的类型错误 : Cannot read property 'documentElement' of null, AjAX

javascript - Angular : Why is my event handled twice?

angularjs - AngularJS 中使用 ui-router 嵌套参数化路由

api - 我应该为外部服务设置哪个超时?

python - 如何在 django 模板中使用 for 循环将列表转换为 html <ul>