Hi I am using MediaPlayer to play my sounds below is my another post http://groups.google.com/group/android-developers/browse_thread/thread/8d1c01b055873f39#
I tried all the possible ways stated in the above post but could not play sounds accordingly so changed the sound code as below, Now the sounds are working fine and no sound is getting skipped but am getting some errors which i cannot figure why they are coming...? Below are some errors: 1- E/MediaPlayer( 2173): stop called in state 1 2- E/MediaPlayer( 2173): stop called in state 2 the above errors i get frequently and i get the below one's randomly, the game freezes and requires a force close when i encounter the below errors 3- E/MediaPlayer( 2173): setDataSource called in state 2 W/System.err( 2173): java.lang.IllegalStateException W/System.err( 2173): at android.media.MediaPlayer.setDataSource(Native Method) 4- E/MediaPlayer( 2173): setDataSource called in state 128 W/System.err( 2173): java.lang.IllegalStateException W/System.err( 2173): at android.media.MediaPlayer.setDataSource(Native Method) W/System.err( 2173): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:247) 5- E/MediaPlayer( 2173): prepareAsync called in state 128 E/MediaPlayer( 2173): setDataSource called in state 128 W/System.err( 2173): java.lang.IllegalStateException W/System.err( 2173): at android.media.MediaPlayer.setDataSource(Native Method) 6- E/MediaPlayerService( 31): offset error E/MediaPlayer( 2173): Unable to to create media player I have observed that all the sounds played atleast once in the game without any error. I want to know what are the states 1,2 & 128 and why are the errors raised. As per the http://developer.android.com/reference/android/media/MediaPlayer.html#Valid_and_Invalid_States I suppose there is no problem in my code but y is that error shown...? Plz check the below code: public void stop() throws MediaException { try { mp.stop(); mp.reset(); FileInputStream fIn = Utils.getContext().openFileInput(fileName); if (fIn != null) { mp.setDataSource(fIn.getFD()); fIn.close(); } } catch(Exception e){e.printStackTrace();} isPlayingSound = false; } public boolean isPlayingSound; //class member MediaPlayer mp = null; String last_req = ""; public void playSound(final String res) { if (isPlayingSound){ return; } try { if (!last_req.equals(res)) { last_req = res; mp = new MediaPlayer(); FileInputStream fIn = Utils.getContext().openFileInput(res); if (fIn != null) { mp.setDataSource(fIn.getFD()); fIn.close(); } mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { public void onCompletion(MediaPlayer mp) { try { mp.stop(); mp.reset(); FileInputStream fIn = Utils.getContext().openFileInput(res); if (fIn != null) { mp.setDataSource(fIn.getFD()); fIn.close(); } isPlayingSound = false; } catch(Exception e){e.printStackTrace();} } }); mp.setOnErrorListener(new MediaPlayer.OnErrorListener() { public boolean onError(MediaPlayer mp, int what, int extra) { mp.release(); mp = null; deleteSoundFile(res); isPlayingSound = false; last_req=""; System.gc(); new PlayerImpl(fileName,fileInputStream); return false; } }); } // mp.prepareAsync(); if (isLooping()) { mp.setLooping(true); } mp.prepare(); mp.start(); isPlayingSound = true; } catch (Exception e) { mp.release(); deleteSoundFile(res); isPlayingSound = false; mp = null; System.gc(); new PlayerImpl(fileName,fileInputStream); last_req=""; playSound(fileName); } } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---