aboutsummaryrefslogtreecommitdiff
path: root/src/js/AudioPlayer.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/AudioPlayer.js')
-rw-r--r--src/js/AudioPlayer.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/js/AudioPlayer.js b/src/js/AudioPlayer.js
new file mode 100644
index 0000000..952f487
--- /dev/null
+++ b/src/js/AudioPlayer.js
@@ -0,0 +1,25 @@
+export default class AudioPlayer{
+ constructor(){
+ this.audioPlayer = new Audio();
+ this.url = window.URL || window.webkitURL;
+ this.soundURL = null;
+ this.attachEventListeners();
+ }
+
+ attachEventListeners(){
+ this.audioPlayer.addEventListener('error', (e)=> {
+ console.log("Error: " + e);
+ }, false);
+ this.audioPlayer.addEventListener('ended', (e)=> {
+ this.audioPlayer = null;
+ this.url.revokeObjectURL(this.soundURL);
+ }, false);
+ }
+
+ play(soundUrl){
+ this.soundURL = soundUrl;
+ this.audioPlayer.src = this.soundURL;
+ this.audioPlayer.play();
+
+ }
+} \ No newline at end of file