As i know,MPVolumeView can add to my app for changing volume.But now i want to control volume with a custom slider. Maybe i can fit it myself if MPVolume was a subclass of uislider,indeed,it is a subclass of uiview. Ask for advices to realize my idea,thank you very much.
6 Answers
UIView *a=[[UIView alloc] init];
for (UIView *view in [volumeSlider subviews]) {
if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) {
a=view;
[(UISlider *)a setThumbImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
[(UISlider *)a setMinimumTrackImage:[UIImage imageNamed:@"volume2.png"] forState:UIControlStateNormal];
[(UISlider *)a setMaximumTrackImage:[UIImage imageNamed:@"volume3.png"] forState:UIControlStateNormal];
}
}
that can do what i want ,but i really don't know if it can pass the apple's checking

- 1,020
- 1
- 15
- 27
-
1So did this pass Apple's review? – Moshe Feb 04 '11 at 21:00
-
2it had passed review,in appstore now! – ben Feb 14 '11 at 05:37
-
1Instead of comparing the description string of a class, I'd use `[view isKindOfClass:[UISlider class]]` instead. Seems cleaner, plus the MPVolumeSlider is a UISlider subclass and this way you don't have a private class name in your binary. – DarkDust Apr 10 '12 at 12:51
If you walk the view hierarchy of MPVolumeView and happen to find a UISlider, you could always customize it.
for ( view in theVolumeView.subviews ) {
if ( [view isKindOfClass:[UISlider class]] ) { ... }
}
Note that there will be other views, and there might not be a UISlider, so make no assumptions. You might want to traverse the hierarchy recursively.

- 53,459
- 16
- 107
- 112
-
oh,there is not any member of class uislider in the MPVolumeView,but there are 3 subViews,i'd like to look up what they are~~ – ben Jul 19 '10 at 05:39
-
Hummm, you could make your own slider but it won't control the volume of the player you want. You will have to work with low level Frameworks like CoreAudio and CoreMedia.
Why don't subclass MPVolumeView? I have never tried subclassing MPVolumeView but you can access @protected stuff by subclassing and @private stuff by adding some categories. You probably want to look at the headers of MPVolumeView to see if there is a UISlider(or something) that you can customize.
UPDATE: (2010/07/21)
I see. Just let me ask u something. Why is neccessary to add a UIProgressView to a VolumeView? In general you would add that to a Player Playback but to its Volume right? the volume does not load like streamming audio or video right?
Second, I just saw the headers of MPVolumeView. And it has a private, also hidden class named MPVolumeViewInternal *_internal; When you have these kind of classes if very difficult to customize without being rejected (when submitting you app to the AppStore) You could make a category and access _internal var but in order to use _internal you will have to have its headers, and this means using private headers and frameworks that are not allowed.
Or you could take a look to the functions in Objective-C runtime Reference and try something like drawnonward suggested to find UISlider of the object you want to modify. Using Obj-C runtime functions is how most tricks or easy-hack are done ;)
-
i really want to know ,whether i could add something else into an API's class.i hope so.thank you – ben Jul 19 '10 at 05:45
-
-
Make a UIView in Interface builder Link against the MP framework Include the MediaPlayer header in your header file that corresponds to the XIB that contains UIView that you just made Change the class of the view you just created to MPVolumeView
It won't work on the simulator, but it does work on devices.

- 11
- 1
Another option would be using the custom slider with MPMusicPlayerController
:
MPMusicPlayerController *controller = [MPMusicPlayerController applicationMusicPlayer];
controller.volume = 0.5; // value in [0,1]

- 10,423
- 9
- 49
- 73
here is the full code of an custom volume slider. it's tested and works on xcode 4.6.1
MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:volumeSlider.bounds] autorelease];
UIView *a=[[UIView alloc] init];
for (UIView *view in [volumeView subviews]) {
if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) {
a=view;
[(UISlider *)a setThumbImage:[UIImage imageNamed:@"slider_thumb.png"] forState:UIControlStateNormal];
[(UISlider *)a setMinimumTrackImage:[UIImage imageNamed:@"slider_progress.png"] forState:UIControlStateNormal];
[(UISlider *)a setMaximumTrackImage:[UIImage imageNamed:@"slider_bg.png"] forState:UIControlStateNormal];
}
}
[volumeSlider addSubview:volumeView];
[volumeView sizeToFit];
you can declare image names at the top or in header file for easier later modifications

- 1,230
- 1
- 22
- 35