简体   繁体   中英

detect audio streaming error in phonegap

I'm streaming from online with the address

http://83.170.109.107:8004

Code looks like

    var snd = new Media(add_list[parameter],onSuccess,onplayError,mediaStatus);
    snd.play();
function onSuccess() {
     console.log("start");
    }
function onplayError(err) {
    console.log("error occurred"+err.code);

}
function mediaStatus(code) {
    console.log(code);

}

This works perfectly when the stream exists on that address.But onSuccess never fired. mediaStatus method is working properly. Now I want to make it error proof. That means if there is no stream exists on an address, it will catch the error and show a message.

So I provided an fake address

 http://184.172.000.000:0000

Now methods are not fired. onSuccess, onplayError & mediaStatus all methods failed. In android LogCat is only showing

12-03 15:41:34.376: E/MediaPlayer(24895): Error (1,-110)

I tried to use try catch , that's not working either. Can anyone please tell me how can I detect if the stream does not exist? And why those methods are not working properly while streaming?

I guess there is no answer for this. So here is what I did. It's not a direct way rather a way around.

I used a function with interval which checks for a fixed amount of time and then fires to see if the app got any stream on the respective address. It it gets any valid stream than it continues and if it doesn't then it consider as the stream doesn't exist. Not a direct but working temporarily for me.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM