This is a useful little bit of code if your iPhone application lets the user set the system volume; it shows how to have your MPVolumeView controller respond to physical button changes.
Fortunately, someone discovered there is a system notifications that is generated whenever the volume changes. Also, the MPVolumeView slider can respond to a message called “_updateVolumeFromAVSystemController” which will cause it to adjust it’s position based on the current system volume level.
So, given the two pieces of information, one can register a notification process to automatically adjust the MPVolumeView slider whenever the volume is changed using the buttons on the side of the phone.
Nifty! And to go with that, in this post there’s a full project demonstrating not only this tip in action but also how to customize its colors, add end icons, etc. Handy if you need it!
[UPDATE: This appears to be obsolete as of System 2.2.1 -- a freshly created MPVolumeView responds to physical buttons just fine. So long as you're targeting the latest OS, no need to worry apparently. The customization tips are still handy though...]
h/t: iPhoneKicks!
Continue Reading →MAR