I have tried threading which proves nothing.  I have even tried making a new
method that threads the mediaplayer's "start();" method like so:

somewhere in the code:

MediaPlayer mp = MediaPlayer.create(this, R.raw.good);
                //mp.release();
                playSound(mp);

then:

    private void playSound(final MediaPlayer mp) {
          new Thread(new Runnable() {
                public void run() {
                    try {
                        mp.prepare();
                    } catch (IllegalStateException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    mp.start();
                }
              }).start();
    }

The same loop, the same mp3, the same evrything, but after 7 loops - it
Force Closes.

Now I'm just lost...
~Douglas.










On Thu, Nov 18, 2010 at 12:44 PM, douglas <weaknetl...@gmail.com> wrote:

> Hello, I am in the middle of creating an application that plays a
> happy sound when you get a question right, and a bad sound when you
> get a question wrong.  Needless to say this is a quiz application.
>
> Now, if I create 2 objects (MEDIAPLAYER) like so:
>
> MediaPlayer mp_e = MediaPlayer.create(this, R.raw.good);
> MediaPlayer mp_e = MediaPlayer.create(this, R.raw.bad);
>
> at the beginning of the application (before my onCreate() where I
> declare/instantiate all other variables) I get a "Force Close."
>
> If i create the objects in the "if answer is right (play good sound),
> else is wrong (play bad sound)," I get a force close after about 7
> questions or so into the quiz. ?
>
> Here is the syntax I used:
>
> if (correct) {
> MediaPlayer mp_f = MediaPlayer.create(this, R.raw.good);
> mp_f.start();
> ...
> next question
> }
> else {
> MediaPlayer mp_f = MediaPlayer.create(this, R.raw.bad);
> mp_f.start();
> ...
> next question
> }
>
> This works up until about question 7 on my AVD device (2.1-update1)
> and question 8 on my Motorola Cliq.
> I ran the "debugger" in Eclipse but I don't see anything useful at
> all.  It looks like Android is breaking and not my code?
>
> If i remove all sound objects and forgo the sound, the application
> runs like a dream.
> I realize that I can do "release();" after playing the sound, from a
> tutorial I read, but that makes the sound not play at all.  I read
> that you need to "reset and prepare" the mp_f MediaPlayer object, but
> that doesn't help either.
>
> Should I be threading these? the sounds are only like 1 maybe 2
> seconds long and never overlap though.  How come it force closes after
> 7? what changes? all of my loop logical concepts stay exactly the same
> as they did from 1 ~ 6, and if I remove the MediaPlayer objects it
> works fine.
>
> I have read everything I can on the subject from the Android Developer
> site and from scraping forums.
> help?  Thanks!
>
> ~Douglas.

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

Reply via email to