We can make use of Salesforce Static Resource to host your Audio or Sound or Music file for playing notification.
Steps:
- Go Static Resource.
- Click New and upload the Audio file.
- Make sure the “Cache Control” is “Public”.
- Click “View file” link to get the URL.
- Use the Static Resource URL in the source tag’s src attribute.
Static Resource:
Sample Code:
<html>
<script>
function playAudio() {
console.log(
'Inside playAudio'
);
let objSound = document.getElementById("AudioId");
objSound.play();
console.log(
'playAudio End'
);
}
</script>
<audio id="AudioId">
<source
src="https://infallibletechie2-dev-ed--c.develop.vf.force.com/resource/1714752960000/SampleMusic"
type="audio/mpeg">
</audio>
<button onclick="playAudio()">
Play Audio
</button>
</html>