Created
October 27, 2019 00:55
-
-
Save ColinMichaels/e48f7b53609f52ebcec0846f87ee31a8 to your computer and use it in GitHub Desktop.
VueJs Plugin using Howler to clean up and easily trigger a sound from anywhere. just by passing it the sound file path.
This file contains 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
import {Howl} from 'howler'; | |
let AudioPlugin = { | |
install: function (Vue, options = {}) { | |
AudioPlugin.events = new Vue(); | |
Vue.prototype.$audio = { | |
play(src,params = {}){ | |
this.load(src).play(); | |
}, | |
load(src){ | |
return new Howl({ src: [src]}) | |
} | |
} | |
}, | |
play: function(src){ | |
this.load(src).play(); | |
}, | |
load: function(src){ | |
return new Howl({ src: [src]}) | |
} | |
}; | |
export default AudioPlugin; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage examples:
@click:
<button @click='"$audio.play('path/sound.mp3')">Play Sound</button>
you will have to register it globally in order to use this anywhere.
let sound = AudioPlugin.load('/path/sound.mp3');
this works identical to howler just added this to only have to import one item to use it individually.