Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Audio. Replacing Element still the same audio file (cached) how to solve?

I am using the HTML5 Audio element inside my HTML file.

Trying many methods,I just cannot manage to replace the audio file via AJAX, it still returns the same audiofile.

<div id="audiodiv">
   <audio id="audioelement">
    <source src="test.ogg" type="audio/ogg">
   </audio>
</div>

So I record a new file called test.ogg which overwrites the old one. I tried using jQuery and using$("#audiodiv").html('') and re-rendering this part. Then fetching the element via document.getElementbyID and then using the .play() function .

It returns the same old test.ogg,which was already overwritten by the new one.

So I tried to delete the cache, still the same problem.

The only way this works is deleting the cache and closing the browser and calling the page again...

How can I solve this?

Thank you very much for help.

like image 200
zer02 Avatar asked Oct 24 '12 00:10

zer02


People also ask

What attribute can make the audio tag or video file to play again after it finished playing?

The loop attribute is a boolean attribute. When present, it specifies that the audio will start over again, every time it is finished.

What is preload in audio HTML?

The preload attribute specifies if and how the author thinks that the audio file should be loaded when the page loads. The preload attribute allows the author to provide a hint to the browser about what he/she thinks will lead to the best user experience. This attribute may be ignored in some instances.

What tag is used to provide alternate file formats for playing audio files?

The <source> tag enables us to specify alternative audio files that the internet browser chooses from. The browser uses the first supported format. The text between the <audio> and </audio> tags displayed in browsers that do not support the <audio> element.


1 Answers

If you're not going to change the name of the file but keep updating it then you need to add immediate Expires HTTP headers to the response on the server side. Exactly how you do this depends on which server you're using. Common ones include Apache and IIS.

However, it would be easier, and also better practice, to let the browser cache the audio and just give each new file a different name.

like image 86
robertc Avatar answered Nov 14 '22 21:11

robertc