我的 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/