Detect if remote asset is valid audio file

I’m loading a (user-generated) MP3 file in my project to be played:

            cc.assetManager.loadRemote(mp3_url, function (err, audioClip) {
                cc.audioEngine.playMusic(audioClip, false);

            }); 

However, I can’t actually know if that is a valid MP3. Is there a way to check if it is a valid MP3?

Thanks! :slight_smile:

You mean that you don’t know if the file can be play properly?

Yes, exactly.

Probably better to check it on your own server.

Is there a way to check if the loaded asset is an MP3 at all?

cc.assetManager.loadRemote(mp3_url, function (err, audioClip) {
            cc.audioEngine.playMusic(audioClip, false);
        });

or can I prevent my app from crashing when

            cc.audioEngine.playMusic(audioClip, false);

is called on a non-MP3 (or corruptly downloaded) file? Something like try… catch?

(Is there a way to do a

try

...

catch 

style handling of exceptions when AudioPlayer stumbles across an unplayable file?)

Which platform are you publishing ?

iOS and Android

Will this enable me to have

 try 

 catch

-style handling of unplayable MP3s?

Sorry, for now there is no way to verify audio file
as Jgod said, it’s better to check it on your own server.

1 Like

I see!

Is there a way to do a

 try 

 catch

construction to catch the exception if an error during playback happens?

Thank you!