Regarding IllegalStateExceptions, MediaPlayer, failed prepares and State codes
I have been struggling quite a lot with our beloved MediaPlayer class... Specifically I want to simply play sounds from some Files... I am getting two specific types of errors actually, and not continuesly but it seems like random... Sometimes 10 files are played rigth away with no errors, then the MediPlayer seems to stop accepting another File... Ok the first error :
- 05-26 15:02:00.916: ERROR/MediaPlayer(25793): error (1, -4)
- 05-26 15:02:00.916: ERROR/setupplayer(25793): java.io.IOException: Prepare failed.开发者_如何学Go: status=0x1
Well for this one I have seen several solutions : use
mp.setDataSource(ins.getFD()); (with ins being an inputstream to my File)
and/or to use
mp.setDataSource(ins.getFD(), 0, f.length());
Both unfortunately won't solve the problem, and I would simply LOVE to know what the very exhaustive error(1,-4) is... And where can I find the codes of the States of the MediaPlayer ? Also I have tried using prepareAsync() instead of prepare() but to be honest it doesn't seem to make any difference at all.. The second error is the Exception which is thrown :
05-26 15:17:30.456: ERROR/playNextPlayer(27303): Error caught : java.lang.IllegalStateException
Which, I guess, might be related to the first error/problem ?
Try mp.setDataSource(String path)
For example,mp.setDataSource("sdcard/1.mp3");
The error is coming because of incorrect path or FileDescriptor.
You should check the State Diagram of Mediaplayer class
精彩评论