Salesforce Static Resource for Audio

Salesforce Static Resource for Audio

We can make use of Salesforce Static Resource to host your Audio or Sound or Music file for playing notification.

Steps:

  1. Go Static Resource.
  2. Click New and upload the Audio file.
  3. Make sure the “Cache Control” is “Public”.
  4. Click “View file” link to get the URL.
  5. 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>

Leave a Reply