• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Porblem with playing sounds with class MediaPlayer

VannyF

Lurker
Hi guys,

I just have started developing for android and do not have much experience. I have the following problem:

I have developed a small game in which small mosquitos appear from time to time on the screen and you have to click on them to kill them. Whenever a mosquito appears a 2 second sound is played via the MediaPlayer class by having a MediaPlayer attribute mp and the following lines
mp.seekTo(0);
mp.start();


So far so good but I have the following problem:

When I am in the game and press the return button the app returns to its homescreen. After about 5 seconds I get an error message saying that the app has stopped. In the logcat I get the following error message:
05-12 07:38:35.740 4327-4327/com.example.td.mueckenfang E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.td.mueckenfang, PID: 4327
java.lang.IllegalStateException
at android.media.MediaPlayer.seekTo(Native Method)
at com.example.td.mueckenfang.GameActivity.eineMueckeAnzeigen(GameActivity.java:199)
at com.example.td.mueckenfang.GameActivity.zeitHerunterzaehlen(GameActivity.java:144)
at com.example.td.mueckenfang.GameActivity.run(GameActivity.java:242)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

The line 199 which is causing the error is the above mentionded line: mp.seekTo(0)

Does anyone have an idea why this problem occurs. I would really appreciate your help. Thank you for your attention
 
Back
Top Bottom