what is the fastest way to check if audio link is invalid (and alert)?
<audio controls src="http://example.com/file/notfound.mp3">
browser not supported
</audio>
Have you tried this?
var myAudio = document.getElementById('myAudio');
myAudio.onerror = function(error) {
console.error(error);
}
With HTML:
<audio id="myAudio" controls src="http://example.com/file/notfound.mp3">
browser not supported
</audio>
Here's the fiddle .
After researching little bit, this is what I found:
$("#postaudiotag").on("click", function () {
try {
$('audio')[0].play();
} catch (e) {
alert('error playing file')
}
});
$("#audiomp3").on("error", function (e) {
alert('mp3 file is not found');
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.