You have to look into the media player API in Android
i.e.android.media.MediaPlayer;
android.media.MediaPlayer.OnCompletionListener . Here it is:
http://developer.android.com/reference/android/media/package-summary.html

And that is how you play a sound on firing a click listener:

            private OnClickListener btnDontBeStupidListener = new
OnClickListener()
            {
                public void onClick(View v)
                {
                  //Toast.makeText(getBaseContext(), "Don't Be Stupid audio file
is being played", Toast.LENGTH_SHORT).show();

                  final MediaPlayer mp = MediaPlayer.create(iMEvil.this,
R.raw.stupid);

                  //mp.start();

                  try {
                          mp.start();
                          //mp.release();
                  }catch(NullPointerException e){
                        Log.v("MP error", e.toString());
                  }

                  mp.setOnCompletionListener(new OnCompletionListener(){

                      // @Override
                      public void onCompletion(MediaPlayer arg0) {
                         mp.release();

                      }
                 });
                }
            };

Hope this helps.

Maqsood
http://www.twitter.com/maxood

On Feb 15, 2:13 pm, Waphomet <[email protected]> wrote:
> Hi everybody, I've been sarching in forums (and google) trying to find
> something helpful but I had no luck, so I hope someone here could help
> me.
>
> I'm trying to make a simple "Piano -like" app, so I can press a button
> and a sound will be playing as long as I'm pressing it. I would also
> like to record in a text file what buttons I've been presing and how
> much time (just similar to midi format), so I could reproduce it
> later.
>
> The question is: what media resource should I use? I should record the
> "plain sounds" in some kind of music format (one archive for each
> sound ) and then call them using soundpool? There's no other more
> optimized option... 'cause I don't like the sound of what I've been
> thinking of...specially if I want to make a composer mode and deal
> with time.
>
> Thanks and sorry for my poor English... greetings from Spain :-) South
> Europe :-)

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to