I have added an mp3 file as a static resource, can someone please help me to call that resource in the lightning component so when I hit the button it will play that static resource as per the Salesforce documentation I have tried below but instead of playing the sound it is displaying the message.
3 Answers
You can use audio tag and specify source of music file in order to play music in Lightning components. For example :
<aura:component>
<audio src="https://chiraglex-dev-ed--c.ap4.content.force.com/servlet/servlet.FileDownload?file=00P6F00002CXedP"
autoplay="true">
</audio>
</aura:component>
You can put this in javascript when a button is pressed.
var playSound = new Audio(urlAudio);
playSound.play();
Play using static resource. Upload a music file to the static resource, copy the link of the file and use in the following fucntion and call it where you want to play the sound.
beep(){
var beepsound = new Audio(Static Resource URL);
beepsound.play();
console.log('beep ');
};