Ahh... I think you nailed it. Right before I checked back for a response, I put on some headphones and heard the _start_ of the sound and then it got cut off.
Would you advise firing this playback off in a service? Is there a recommended way of doing this? Thanks, Donn On Tue, Jun 23, 2009 at 2:01 PM, Marco Nelissen <marc...@android.com> wrote: > > On Tue, Jun 23, 2009 at 6:56 AM, Donn Felker<donnfel...@gmail.com> 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. > > > > -- Donn http://blog.donnfelker.com/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---