V
V
vadim_tur2015-10-09 17:52:10
JavaScript
vadim_tur, 2015-10-09 17:52:10

How to check if an mp3 file exists?

I have links to audio files on my own server. When you click on the link, this file is played through the js player, but before playing, you need to check if this file exists on the server and if not, perform certain actions. Unfortunately, the player itself does not provide such an opportunity and simply gives an error that the file is missing. How to do it?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivanq, 2015-10-09
@Ivanq

Write:

$.ajax("http://yoursite.ru/your/cool/path/your_cool_file.mp3", {
    success: function() {
        // Run your mp3 player
    },
    error: function() {
        alert("An error occured. We can not play the audio");
    }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question