Plies Neyo
Plies Neyo

Reputation: 247

Control Master Volume - iPhone, Cocoa Touch

I'm wanting to control the master volume of the iPhone with a UISlider. There is a way of doing it without code and I've forgot how to. So code or within the xib, how do I do this?

Thanks

Upvotes: 3

Views: 1074

Answers (2)

Mathew Varghese
Mathew Varghese

Reputation: 4527

Assuming you already have an instance of the MPVolumeView class, you need to search its subviews to find the MPVolumeSlider view:

UISlider *volumeViewSlider;

// Find the MPVolumeSlider
for (UIView *view in [volumeView subviews])
{
   if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) 
   {
       volumeViewSlider = view;
   }
}

[volumeViewSlider setValue: 1.0f animated:YES];
[volumeViewSlider _commitVolumeChange];

Hope this helps you out.

Upvotes: 0

Panshul
Panshul

Reputation: 966

You can try the following method: Place it in your XIB.

  1. Open the XIB where you want to place to slider into
  2. Add a UIView to your view
  3. Change the class identity from UIView to MPVolumeView
  4. Change backgroundColor to clear

Upvotes: 2

Related Questions