Created
August 7, 2015 08:20
-
-
Save gperrudin/a0b7f07e758b3bec2324 to your computer and use it in GitHub Desktop.
HTML5 audio blocking Ionic app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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