Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
Modify download file name in html5 audio tag

I am working with an audio tag whose source can be one of several types but called from an ashx file, as I am dynamically loading the stream.

<audio id="audio" controls="" autoplay="" download="soundFile.wav">
  <source id="mp3" src="../Controls/SoundPlayer/GetSoundFile.ashx?soundType=Sound&amp;fileId=test&amp;fileType=mp3" type="audio/mpeg3">
  <source id="wav" src="../Controls/SoundPlayer/GetSoundFile.ashx?soundType=Sound&amp;fileId=test&amp;fileType=wav" type="audio/wav">
</audio>

This part works fine, but what I'd like to do is catch an error when it fails. Which I can do like so:

$('audio').on('error', function (e) {
    $('#divAudioPlayerMessage').text('Recording can’t be played');
});
$('source').on('error', function (e) {
    $('#divAudioPlayerMessage').text('Recording can’t be played');
});

Or like so (which apparently really only works in IE [I got this from How to check if HTML5 audio has reached different errors)

document.getElementsByTagName('audio')[0].addEventListener('error', function(e, o) {
    // audio playback failed - show a message saying why
    // to get the source of the audio element use $(this).src
    var errorMessage = '';
    switch (e.target.error.code) {
        case e.target.error.MEDIA_ERR_ABORTED:
            errorMessage = 'You aborted the video playback.';
            break;
        case e.target.error.MEDIA_ERR_NETWORK:
            errorMessage = 'A network error caused the audio download to fail.';
            break;
        case e.target.error.MEDIA_ERR_DECODE:
            errorMessage = 'The audio playback was aborted due to a corruption problem or because the video used features your browser did not support.';
            break;
        case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED:
            errorMessage = 'The video audio not be loaded, either because the server or network failed or because the format is not supported.';
            break;
        default:
            errorMessage = 'An unknown error occurred.';
            break;
    }
    $('#divAudioPlayerMessage').text(errorMessage);
}, true);

My question is how do I tell what the actual error is. For example, in my ashx file I might return a 404 error, which if I get I would like to give a specific message.

As well, my other problem, is that when running in Chrome or Firefox, who do not support mp3, my error handler will be called, but I would like to ignore that error since I also have a wav file which is supported.

Thank you!

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!