Objective-C Troublesome MPVolumeView

April 19, 2009 § 1 Comment

This is probably the only way to control the system volume. However MPVolumeView is poorly documented with little flexibility.

MPVolumeView is part of MediaPlayer. If you use the MediaPlayer to play the audio, it calls up a stand-alone screen.

Below is a work around to use MPVolumeView to control the system volume for the app, not specific to play a single audio file.

Add framework MediaPlayer.framework to your project.

Add this line to .h header file:
#import <MediaPlayer/MediaPlayer.h>

Add code to .m source file:
volumeView = [[[MPVolumeView alloc] initWithFrame:CGRectMake(200,100,100,200)] autorelease];
[volumeView sizeToFit];
[self.view addSubview:volumeView];

Basically when the users change volume, the system volume will change immediately. It provides you the UISlider so you don’t have to create UISlider object.

However the application is very limited. First it won’t work at all for landscape orientation. No matter how you customize it with UISlider properties and rotate it, it won’t work. Secondly, avoid to put it to – (void)viewDidLoad method on the MainViewController, it would crash.

Putting the MPVolumeView on the main app is not a good idea. Many apps leave the volume control on views other than the MainView.

From researching around, I’ve found a Notification class you can use for volume change. I should alert that it is not tested.

[[NSNotificationCenter defaultCenter] addObserver:self

// Method

– (void) volumeChanged:(NSNotification *)notify
[volumeView _updateVolumeFromAVSystemController];


§ One Response to Objective-C Troublesome MPVolumeView

  • Don Susini says:

    Just so others looking for this code know, any use of the private API call to: _updateVolumeFromAVSystemController will get your app rejected by Apple now.

    There have been several new apps that control the system volume, so I’m researching now to see if there’s a workaround for this. I’ll post it here if I find it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

What’s this?

You are currently reading Objective-C Troublesome MPVolumeView at Web Builders.


%d bloggers like this: