简体   繁体   English

在phonegap中检测音频流错误

[英]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. 当流存在于该地址上时,此方法非常有效。但是onSuccess从未触发。 mediaStatus method is working properly. mediaStatus方法运行正常。 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. onSuccess,onplayError和mediaStatus所有方法均失败。 In android LogCat is only showing 在android中LogCat仅显示

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

I tried to use try catch , that's not working either. 我尝试使用try catch ,这也不起作用。 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. 不是直接的,而是为我临时工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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