On Tue, Jun 23, 2009 at 6:56 AM, Donn Felker<[email protected]> wrote:
>
> I'm developing an application that responds to certain accelerometer
> events such as movements to the left or right when a certain delta is
> reached. When these deltas are fired I want to play a sound with the
> MediaPlayer.
>
> I'm using the Sensor Simulator by Open Intents to simulate sensor
> events. I have the code set up, and I also have some basic
> android.util.Log.e(...) statements telling me when these events are
> fired. When I simulate the sensor, my deltas are met and my log
> statements are output to LogCat. Therefore I know this is working.
>
> However, I now want to play an audio resource file (mp3).
>
> I added a method inside of the SensorListener definition called
> PlayMedia(). This simply does the following:
>
>
>                private void PlayMedia()
>                {
>                        if(mp != null)
>                        {
>                                android.util.Log.e("test","mp is not null, 
> cleaning up!");
>                                if(mp.isPlaying())
>                                {
>                                        android.util.Log.e("test","Stopping 
> the mp!");
>                                        mp.stop();
>                                }
>                        }
>                        // is not playing.
>                        android.util.Log.e("test","creating a new mp");
>                        mp = MediaPlayer.create(getApplicationContext
> (),com.MyCompany.Apps.MyApp.R.raw.mySound);
>
>                        android.util.Log.e("test","Start the sound");
>                        mp.start();
>                        mp.reset();

MediaPlayer.start() only starts playback, it does not wait for
playback to complete, and so that call to reset() will cause playback
to stop, probably before any sound is played.

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