iOS 7: MPMusicPlayerController volume deprecated. How to change device volume now?
To answer you question exactly:
Yes there is other way to change system volume without user interaction.
Until recent times I used to think that changing volume using MPVolumeView programmatically is possible only using private API. But I have just verified, that changing the value of volumeSlider and faking slider's touchUP event works:
MPVolumeView* volumeView = [[MPVolumeView alloc] init];
//find the volumeSlider
UISlider* volumeViewSlider = nil;
for (UIView *view in [volumeView subviews]){
if ([view.class.description isEqualToString:@"MPVolumeSlider"]){
volumeViewSlider = (UISlider*)view;
break;
}
}
[volumeViewSlider setValue:1.0f animated:YES];
[volumeViewSlider sendActionsForControlEvents:UIControlEventTouchUpInside];
(When slider receives touchUP event, it will invoke _commitVolumeChange
method on itself, which will change the system volume)
iOS: Change Device Volume
Using iPodMusicPlayer would affect the actual iPod volume setting as well. If you want to avoid that, use this:
#import
// ...
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
musicPlayer.volume = 1.0f;
As the user holex correctly mentioned the property volume
in MPMusicPlayerController
is deprecated in iOS 7.
Volume control with MPMusicPlayerController
These are the images I use - I've only included the 1x sizes - thumb is 54 x 30
[self.mpVolumeView setMinimumVolumeSliderImage:[UIImage imageNamed:@"master_volume_bar"] forState:UIControlStateNormal];
[self.mpVolumeView setMaximumVolumeSliderImage:[UIImage imageNamed:@"grey_volume_bar"] forState:UIControlStateNormal];
[self.mpVolumeView setVolumeThumbImage:[UIImage imageNamed:@"volume_thumb"] forState:UIControlStateNormal];
how to Control iOS system Volume using a UISlider
I love new learners... Simple answer for you...
First create a UIView
in your StoryBoard, where you want to put a volume slider.
Now create a IBOutlet
for that view in your ViewController implementation.
for ex:
@property (nonatomic,strong) IBOutlet UIView* volumeView;
Now in the viewDidLoad
method write the following code:
MPVolumeView *mpVolumeView = [[MPVolumeView alloc]initWithFrame:self.volumeView.bounds];
[self.volumeView addSubview:mpVolumeView];
[mpVolumeView sizeToFit];
Now you will have volume control in your app...
Note: this code will not work for a simulator.
cheers.
Related Topics
Do Something Every X Minutes in Swift
Swift Saving and Retrieving Custom Object from Userdefaults
Uisplitviewcontroller in Portrait on Iphone Shows Detail Vc Instead of Master
How to Play a Local Video With Swift
Stringbyappendingpathcomponent Is Unavailable
Firebase Notification Records/Log API
Xcode 6: Keyboard Does Not Show Up in Simulator
Uibutton Custom Font Vertical Alignment
The Model Used to Open the Store Is Incompatible With the One Used to Create the Store
How to Customize the Background Color of a Uitableviewcell
How to Write Text on Image in Objective-C (Ios)
When to Use Dequeuereusablecellwithidentifier VS Dequeuereusablecellwithidentifier: Forindexpath
Uitapgesturerecognizer Breaks Uitableview Didselectrowatindexpath
How to Get the Name of Image Picked Through Photo Library in Iphone
How to Disable Copy Paste Option from Uitextfield Programmatically