How to add volume level control in iPhone app?

Featured Image

Now, here is something from MediaPlayer framework that we are going to use if we want in most easiest way control level of volume in our application. This is very useful if you are implementing an audio player in your app.

The best thing about this small feature is easy implementation in any class. We just import MediaPlayer framework in header of our class (#import <MediaPlayer/MPVolumeView.h>) and add this code below in method we know that is appropriate for this feature (init method).

 MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:CGRectMake(0, 0, 200, 20)] autorelease]; = CGPointMake(150,370);
[volumeView sizeToFit];
[self.view addSubview:volumeView]; 

This kind of volume control is connected with iPhone hardware volume buttons. You get same thing like in Music player.

And that is all.


Care to rate this post?


Ivan Kalaica

Ex. Inchooer

At Inchoo, Ivan Kalaica was an iOS SDK developer. He worked with us from 2008. to 2012.

Other posts from this author

Discussion 0 Comments

Add Comment

Add Your Comment

Please wrap all source codes with [code][/code] tags.