On Thu, Apr 30, 2009 at 9:46 AM, westmeadboy <mjc1...@googlemail.com> wrote:
> > On Apr 30, 9:29 pm, Marco Nelissen <marc...@android.com> wrote: > > No, the fact that a "getState()" method would be unreliable is reason > enough > > not to have one. > > Its no less reliable then any other call to any non-synchronized > getter method and there are plenty of those in the Android SDK. > > An onStateChangedListener method would definitely be helpful. It might make it easier for you to retrieve an unreliable bit of information, but you would still have to deal with all the same exceptions and other errors that you can run in to now, precisely because the state information is unreliable. I think you're looking at this the wrong way around (and perhaps the documentation is to blame for that). If the documentation for MediaPlayer.foo() says it will throw an exception if you're not in state X, Y or Z, that doesn't mean that prior to calling MediaPlayer.foo() you should check that the state is X, Y or Z. It just means that when you get an exception, it was probably because you were not in any of those states, and you should do whatever you need to do recover (which in most cases will be to reset() the MediaPlayer and start over). In some cases, it's not a problem to ensure that MediaPlayer is in a certain state. For example, if you call prepare(), and it succeeds, then MediaPlayer is in the 'prepared' state, and it won't suddenly 'unprepare' itself. In other cases, in particular once you've started playback, it's not so clear cut. For example, once you call start(), MediaPlayer will transition to the 'playing' state, but it can drop out of that state at any time, for a number of reasons (such as an error during playback, or reaching the end of the file). If you were to ask it for its state, and it returns 'playing', and you then decide that because it is playing, it is safe to call MediaPlayer.pause(), you will still have to deal with the possibility of playback having reached the end by the time your code calls pause(), and your OnErrorListener being called as a result. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---