-1

I've a music player app and I wanna control system volume through a UISlider How can I do it? I've searched google and stack overflow but its showing something related to MPMusicPlayerController and MPVolumeView and that too not easy to understand. Is there any API for It. please do help.

SUDHAKAR RAYAPUDI
  • 549
  • 1
  • 9
  • 18

4 Answers4

2

No API's required at all.

If you're a beginner, you should go through MPVolumeView from the Apple Documentation. Everything is given there in detail. Just have a look at it.

It says:

Use a volume view to present the user with a slider control for setting the system audio output volume, and a button for choosing the audio output route. When first displayed, the slider’s position reflects the current system audio output volume. As the user drags the slider, the changes update the volume. If the user presses the device volume buttons while sound is playing, the slider moves to reflect the new volume.

Bhavin
  • 27,155
  • 11
  • 55
  • 94
2

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.

1

No API is needed. That's the whole point. MPVolumeView just works. It is a slider that controls system volume. Make one, stick it in the interface, done.

matt
  • 515,959
  • 87
  • 875
  • 1,141
1

MPVolume view should do the job. Here are couple of examples:

iOS 7: MPMusicPlayerController volume deprecated. How to change device volume now?

https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPVolumeView_Class/

but if you need custom interface:

 // Set the value of slider to system volume control
 [[MPMusicPlayerController systemMusicPlayer] setVolume:self.mySlider.value];

possibly you also need to use this:

 // Set it somewhere in your code
 [self.moviePlayer setUseApplicationAudioSession:YES]; // this generates a depreciation warning
Community
  • 1
  • 1
NeverHopeless
  • 11,077
  • 4
  • 35
  • 56