Skip to content

Instantly share code, notes, and snippets.

@gperrudin
Created August 7, 2015 08:20
Show Gist options
  • Save gperrudin/a0b7f07e758b3bec2324 to your computer and use it in GitHub Desktop.
Save gperrudin/a0b7f07e758b3bec2324 to your computer and use it in GitHub Desktop.
HTML5 audio blocking Ionic app
angular.module('app')
/*
Manages the global audio player with the HTML5 audio player
See HTML5 audio player API : http://www.w3schools.com/tags/ref_av_dom.asp
*/
.factory('Player', function ($rootScope, Station, Error, $document, $window) {
return {
player : $document[0].createElement('audio'),
setPlayer : function(player) {
this.player = player;
},
getPlayer : function() {
return this.player;
},
// Plays the current radio station (see the Station factory)
play : function() {
this.player.src = Station.getCurrentStation().url;
this.player.play();
return;
},
// Pauses the current radio station
pause : function() {
if(this.playing) {
this.player.pause();
return;
}
Error.new("Can't pause because not playing.")
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment