Try:
<script type="text/javascript">
window.addEventListener('load', () => {
var audio = document.createElement("audio");
var asrc = document.createElement("source");
asrc.setAttribute('src', "/files/chat-space/4928f76ff3258fcca32bb75d5d043237");
audio.appendChild(asrc);
audio.play();
});
</script>
Notes:
The window.addEventListener('load')
tells the page not to try playing the audio until all HTML and resources are loaded/available.
The audio tag does not have a src=
attribute — it has a child element, <source>
, and that element has the src=
attribute.
FWIW, I just tested the above code on a live server, using a standard mp3 audio file. If this code does not work for you, first try it with a standard .mp3 file (to ensure the problem is not with specifying the audio file).
If it still doesn't work, please tell us more about your environment.
See:
https://www.w3schools.com/TAGS/tag_audio.asp
audio.onerror=function(e) {console.log(e)}
and look at the console to see what's happening. I also would try to add a source with type set. – ZeroWorks