[英]Modify download file name in html5 audio tag
我正在使用一個音頻標簽,它的源可以是多種類型之一,但從 ashx 文件中調用,因為我正在動態加載流。
<audio id="audio" controls="" autoplay="" download="soundFile.wav">
<source id="mp3" src="../Controls/SoundPlayer/GetSoundFile.ashx?soundType=Sound&fileId=test&fileType=mp3" type="audio/mpeg3">
<source id="wav" src="../Controls/SoundPlayer/GetSoundFile.ashx?soundType=Sound&fileId=test&fileType=wav" type="audio/wav">
</audio>
這部分工作正常,但我想做的是在失敗時捕獲錯誤。 我可以這樣做:
$('audio').on('error', function (e) {
$('#divAudioPlayerMessage').text('Recording can’t be played');
});
$('source').on('error', function (e) {
$('#divAudioPlayerMessage').text('Recording can’t be played');
});
或者像這樣(這顯然只適用於 IE [我從如何檢查 HTML5 音頻是否達到不同的錯誤中得到了這個)
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);
我的問題是如何判斷實際錯誤是什么。 例如,在我的 ashx 文件中,我可能會返回一個 404 錯誤,如果我得到它,我想給出一個特定的消息。
同樣,我的另一個問題是,當在不支持 mp3 的 Chrome 或 Firefox 中運行時,我的錯誤處理程序將被調用,但我想忽略該錯誤,因為我也有一個支持的 wav 文件。
謝謝!
如果您想更改音頻標簽的可下載文件名,則意味着
<audio controls="" title='example' />
默認情況下,音頻標簽將以 .wav 格式下載。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.