[android-developers] Re: A safer way of using SoundPool?
On Feb 16, 6:25 am, Marco Nelissen marc...@android.com wrote: Why do you say it's not a public API? SoundPool is undocumented because it is not ready as a public API and is subject to change. http://groups.google.com/group/android-developers/msg/6c360f2d0662be0a -- Jon --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[android-developers] Re: A safer way of using SoundPool?
Great idea, Jon. Thanks for sharing the code. I'm about to start work on sound in my game, so I'll look into using this. Hopefully, Google realizes that many are using SoundPool and will keep the existing API in place for a while, even if deprecated, long enough to migrate apps. I think we are all interested in keeping Android's good name and not annoying users without need. On Feb 16, 2:05 am, Jon Colverson jjc1...@gmail.com wrote: On Feb 16, 6:25 am, Marco Nelissen marc...@android.com wrote: Why do you say it's not a public API? SoundPool is undocumented because it is not ready as a public API and is subject to change. http://groups.google.com/group/android-developers/msg/6c360f2d0662be0a -- Jon --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[android-developers] Re: A safer way of using SoundPool?
I believe we were able to do the fixes for SoundPool without changing the public API. There are no plans to deprecate it at this time. On Feb 16, 6:05 am, Blake B. bbuckle...@yahoo.com wrote: Great idea, Jon. Thanks for sharing the code. I'm about to start work on sound in my game, so I'll look into using this. Hopefully, Google realizes that many are using SoundPool and will keep the existing API in place for a while, even if deprecated, long enough to migrate apps. I think we are all interested in keeping Android's good name and not annoying users without need. On Feb 16, 2:05 am, Jon Colverson jjc1...@gmail.com wrote: On Feb 16, 6:25 am, Marco Nelissen marc...@android.com wrote: Why do you say it's not a public API? SoundPool is undocumented because it is not ready as a public API and is subject to change. http://groups.google.com/group/android-developers/msg/6c360f2d0662be0a -- Jon --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[android-developers] Re: A safer way of using SoundPool?
Why do you say it's not a public API? On Sun, Feb 15, 2009 at 10:09 PM, Jon Colverson jjc1...@gmail.com wrote: The presence of SoundPool in the SDK causes a bit of a dilemma for those of us developing games. On the one hand, it's not a public API and it might go away or change in future releases, breaking our games and annoying our users. On the other hand, it does provide a noticeable performance improvement over using MediaPlayers, and I have to assume that my competitors will be using it to eek out as much performance as possible. So after changing my mind a few times, I've decided that I will use SoundPool in my game, but I've come up with a compromise that will hopefully stop it from breaking if the API changes later: Attached is a set of classes that wrap SoundPool by loading the class dynamically at runtime via reflection, and if it isn't found or doesn't support the expected methods, falls back on a wrapper around MediaPlayer that implements a (very) small subset of the SoundPool API. It's very basic and only supports playing non-looping sounds with variable volume, so it won't help if you need pitch changing, but if you just want SoundPool for its performance then it might be useful. Here's how to use it: int maxStreams = 16; ISoundPool sp = SoundPoolProxy.bestSoundPool(maxStreams, AudioManager.STREAM_MUSIC, 100); int s = sp.load(context, resource, 0); float leftVolume = 1, rightVolume = 1; sp.play(s, leftVolume, rightVolume, 0, 0, 1); Some caveats: As mentioned by others, if you try to play more than maxStreams sounds at the same time then SoundPool will deadlock. It might still break if the API changes in the future without changing the method signatures (so the parameters have different meanings). If that causes an exception in SoundPool then my wrapper will throw a RuntimeException up to you, so you could catch them if you'd prefer for sound to fail silently instead of crashing your app. Calling SoundPool's methods via reflection involves a certain amount of overhead. In my tests the average call time was 3.439ms, compared with 3.088ms when calling SoundPool directly, so an 11% overhead. -- Jon --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---