1

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.

enter image description here

1
  • 3
    ui:message is a TTS service, not for playing arbitrary audio files.
    – sfdcfox
    Sep 10, 2018 at 9:39

3 Answers 3

3

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>
0

You can put this in javascript when a button is pressed.

 var playSound = new Audio(urlAudio);
    playSound.play();
0

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 ');

};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.