Skip to content

Commit 48ff267

Browse files
committed
Merge pull request #517 from satyakb/satya/state-update
Fixes #476 by calling $scope.$apply() when state is changed outside of the angular context.
2 parents 238a525 + 97d7fec commit 48ff267

2 files changed

Lines changed: 25 additions & 15 deletions

File tree

app/public/js/common/songDirective.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ app.directive('song', function ($rootScope, $window, playerService) {
99
elem.bind('click', function () {
1010
currentEl = this;
1111

12-
playerService.songClicked(currentEl);
12+
$scope.$apply(function() {
13+
playerService.songClicked(currentEl);
14+
});
1315
});
1416

1517
}

app/public/js/player/playerCtrl.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ app.controller('PlayerCtrl', function ($scope, $rootScope, playerService, queueS
117117
var playPause = new gui.Shortcut({
118118
key: 'MediaPlayPause',
119119
active: function() {
120-
if ( $rootScope.isSongPlaying ) {
121-
playerService.pauseSong();
122-
} else {
123-
playerService.playSong();
124-
}
120+
$scope.$apply(function() {
121+
if ( $rootScope.isSongPlaying ) {
122+
playerService.pauseSong();
123+
} else {
124+
playerService.playSong();
125+
}
126+
});
125127
},
126128
failed: function() {
127129
// nothing here
@@ -131,9 +133,11 @@ app.controller('PlayerCtrl', function ($scope, $rootScope, playerService, queueS
131133
var stop = new gui.Shortcut({
132134
key: 'MediaStop',
133135
active: function() {
134-
if ( $rootScope.isSongPlaying ) {
135-
playerService.pauseSong();
136-
}
136+
$scope.$apply(function() {
137+
if ( $rootScope.isSongPlaying ) {
138+
playerService.pauseSong();
139+
}
140+
});
137141
},
138142
failed: function() {
139143
// nothing here
@@ -143,9 +147,11 @@ app.controller('PlayerCtrl', function ($scope, $rootScope, playerService, queueS
143147
var prevTrack = new gui.Shortcut({
144148
key: 'MediaPrevTrack',
145149
active: function() {
146-
if ( $rootScope.isSongPlaying ) {
147-
playerService.playPrevSong();
148-
}
150+
$scope.$apply(function() {
151+
if ( $rootScope.isSongPlaying ) {
152+
playerService.playPrevSong();
153+
}
154+
});
149155
},
150156
failed: function() {
151157
// nothing here
@@ -155,9 +161,11 @@ app.controller('PlayerCtrl', function ($scope, $rootScope, playerService, queueS
155161
var nextTrack = new gui.Shortcut({
156162
key: 'MediaNextTrack',
157163
active: function() {
158-
if ( $rootScope.isSongPlaying ) {
159-
playerService.playNextSong();
160-
}
164+
$scope.$apply(function() {
165+
if ( $rootScope.isSongPlaying ) {
166+
playerService.playNextSong();
167+
}
168+
});
161169
},
162170
failed: function() {
163171
// nothing here

0 commit comments

Comments
 (0)