So if I load a large sound from a resource, is there any way to tell if it's ready to play? I wish there was an isPrepared method for media player. As it stands now there seems like there's no way to know for sure.
On Mar 1, 2009 11:40 PM, "Marco Nelissen" <marc...@android.com> wrote: On Sun, Mar 1, 2009 at 7:40 AM, madcoder <paperga...@gmail.com> wrote: > > I thought I had solved this problem here > > http://groups.google.com/group/android-developers/browse_thread/thread/260f2951d4a23445/d676c2a7d6b66c20?hl=en&lnk=gst&q=onpreparedlistener#d676c2a7d6b66c20 > > but apparently not. > > > I have successfully implemented the Media Player for my apps, but when > I tried to use some of the callback methods I ran into a problem. > > What I'm trying to do is use Media Player in a reusable (library) > class. This stand-alone library class (call it MyMediaPlayer) is > created by passing the Activity Context to it's constructor. I then > use getApplicationContext to avoid any potential memory leaks. > > My problem is trying to use callbacks. When I implement > MediaPlayer.OnPreparedListener in my library class, it doesn't ever > get called. > > To test this further, I created a separate project, that has a single > activity, that also implements the OnPreparedListener. In that > project, the onPreparedListener is called, and it works. > > Both are coded this way: > > (mp = MediaPlayer, and the MyMediaPlayer class implements/overrides > OnPreparedListener) > > mp = MediaPlayer.create(context, resourceId); > mp.setOnPreparedListener(this); MediaPlayer.create() calls prepare() internally, so it doesn't seem that useful to set an onPreparedListener after prepare() has already finished. The fact that it works in your Activity is not something you should rely on. It only works in your Activity because the callbacks are posted to the main Looper, and in this case your main loop isn't going to process the callback event until after you've set the listener, even though in reality prepare() has already finished by the time you set the listener. I'm guessing that when you do this in your library, you're doing it from another thread, and so the event is either dropped because that thread doesn't have a Looper, or it is processed in the main Looper before your thread gets around to calling setOnPreparedListener(). --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---