MediaPlayer Streaming issues on Android 4.4 (API 19)

南楼画角 提交于 2019-12-23 09:38:12

问题


My app is having issues with the MediaPlayer streaming, specifically on Nexus 5. I'm not sure if this is Nexus 5 or API level 19 causing the problem. Basically my MediaPlayer gets prepared and I call MediaPlayer.start(), but the MediaPlayer doesn't begin streaming.

This happens at random and only on my Nexus 5 device. When this happens, if I try seeking the MediaPlayer it begins to play. Is anyone else experiencing this?

UPDATE: I've filed a bug against Android: https://code.google.com/p/android/issues/detail?id=62304


回答1:


Not sure if it's related, I had similar issue with local file playback, only on 4.4 occasionally, not reproducible on 4.3. This only happens when I want to play a new song reusing the existing MediaPlayer.

Solution: I had to call stop(); before reset(); and setDataSource():

    stop();
    reset();

    try {
        setDataSource(context, uri);
        prepareAsync();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }



回答2:


time solution: in onprepare before start try this code:

if (mSeekWhenPrepared != 0) {
            seekTo(mSeekWhenPrepared);
        } else {seekTo(0);}


来源:https://stackoverflow.com/questions/19916293/mediaplayer-streaming-issues-on-android-4-4-api-19

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!