From ecc12b2ef3b058ddd8bf9612afd7c9276f0386f9 Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Tue, 14 Aug 2018 11:05:32 +0530 Subject: * removed unwanted dependencies * improved compression * Introduces Audio Player :sparkles: :fire: :racehorse: :snowflake: :gem: --- src/js/AudioPlayer.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/js/AudioPlayer.js (limited to 'src/js/AudioPlayer.js') 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 -- cgit v1.2.3