问题
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