One should always keep the "house" clean. Nevertheless they should  
have predicted this.

Hugo Veiga
[EMAIL PROTECTED]

On Oct 11, 2008, at 6:01 PM, Ludwig <[EMAIL PROTECTED]> wrote:

> Just revisiting this: the documentation actually states that you  
> have to call release() on the mediaplayer when you are done with it.
> I suggest that you use the following pattern to ensure that at any  
> one time the media player (at least as far as your application is  
> concerned) will only play one thing:
>
> private MediaPlayer mMediaPlayer = null;
>
> public void onClick(View view) {
>                       if (mMediaPlayer != null) {
>                               mMediaPlayer.stop();
>                               mMediaPlayer.release();
>                       }
>                       mMediaPlayer = MediaPlayer.create(this, R.raw.a1);
>                       mMediaPlayer.start();
>
> I have tried this by simply putting it in a loop within the onClick  
> method: if I run just the last two lines (without the cleanup) a  
> hundred times, it will blow up with a NullPointerException. With the  
> resource management, it does work.
>
> However, I still think it is shoddy design on the Android front. In  
> a component-based architecture components should manage their  
> resources and not just blow up. The requirement to call release()  
> takes us back to good-old C times when you are trying to track all  
> your pointers. Programming has moved on a bit since then.
>
> Ludwig
>
>
>
> 2008/10/11 Ludwig <[EMAIL PROTECTED]>
> I have tried this and I can confirm that when you click a button  
> with an onClick() method defined as I suggested, that it will fail  
> when clicked many times in short succession.
>
> Looking at the debug messages, it looks like that the mediaplayer is  
> simply running out of filehandles and then crashes because it cannot  
> open any more files. That situation should be handled inside the  
> mediaplayer code.
>
> This is a bit worrying as it shows that Android has not really been  
> stress tested by Google: it makes Android look a bit as if it was  
> coded by novices. I think it would be best to file a bug report.  
> Internally it should be relatively easy to fix with a bit of  
> resource management: does it really make sense to try to play dozens  
> of sound files at the same time?
>
> Ludwig
>
> 2008/10/10 [EMAIL PROTECTED] <[EMAIL PROTECTED]>
>
>
> > What would be wrong with this:
> > @Override
> > public void onClick(View view) {
> > MediaPlayer mp = MediaPlayer.create(this, R.raw.a2);
> > mp.start();
> >}
>
> In this case I can to click only 27 times.
> Then I hve exception - NullPointerException
>
> In m5 worked variant:
>
> if( mSoundFx != null )
>      mSoundFx.pause();
> mSoundFx = mSoundFxs[aBonusType];
> mSoundFx.seekTo(0);
> mSoundFx.start();
>
> where mSoundFx - MediaPlayer mSoundFx;
> and mSoundFxs  - MediaPlayer  mSoundFxs = new MediaPlayer[]{
> MediaPlayer.create( mContext,R.raw.no2),
> MediaPlayer.create( mContext,R.raw.trc_ok2),
> MediaPlayer.create( mContext,R.raw.type2) ,
> MediaPlayer.create( mContext,R.raw.side2),
> MediaPlayer.create( mContext,R.raw.appl2),
> };
>
> But in 9beta and 1.0_r1 it does not work.
>
>
>
>
>
> >

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to