my MusicPlayer.js
Angular service has a callback function wrapped in $rootScope.$apply
that updates a specific object (musicPlayer.currentPlaybackTime
) and is shared to all other controllers ( via applying to $rootScope
).
I understand that you'll ideally want to limit any $rootScope
pollution, so i'm looking at possible refactoring options that take away calling apply methods to $rootScope
but allows my updated object to be shared across multiple controllers.
My research indicates that i'll need to register the other controllers (i.e. PlayerDashboardCtrl.js
, PlaylistCtrl.js
and AlbumListCtrl.js
) that need my currentPlaybackTime
object, but i'd like to understand what's the most efficient way of doing this.
Thank you.
var setSong = function(song) {
currentBuzzObject = new buzz.sound(song.audioUrl, {
formats: ['mp3'],
preload: true
});
currentBuzzObject.bind('timeupdate', function() {
$rootScope.$apply(function() {
musicPlayer.currentPlaybackTime = currentBuzzObject.getTime();
});
});
musicPlayer.currentSong = song;
};