简体   繁体   English

MediaPlayer的WiFi连接丢失时没有错误事件

[英]No error event when WiFi connection is lost for MediaPlayer

I have registered an OnErrorListener with my MediaPlayer and to test it I simply turn off the WiFi. 我已经使用我的MediaPlayer注册了一个OnErrorListener并测试它我只需关闭WiFi。 There is no other Internet connection available than WiFi so the playback stops, but the event handler is not fired. 除了WiFi之外没有其他可用的Internet连接,因此播放停止,但不会触发事件处理程序。 Isn't that supposed to happen or how would I deal with these problems? 不应该发生这种情况或者我将如何处理这些问题?

MediaPlayer mp = new MediaPlayer();
mp.setDataSource(uri);
mp.setOnErrorListener(new MediaPlayer.OnErrorListener() {
    @Override
    public boolean onError(MediaPlayer mediaPlayer, int what, int extra) {
        // logging stuff
        return false;
    }
});

mp.prepare();
mp.start();

I think that the MediaPlayer class does not count that as an error. 我认为MediaPlayer类不会将其视为错误。 You could try using setOnBufferingUpdateListener . 您可以尝试使用setOnBufferingUpdateListener According to the documentation, this is called 根据文档,这称为

when the status of a network stream's buffer has changed. 当网络流缓冲区的状态发生变化时。

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

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