tags:

views:

52

answers:

3

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.

+1  A: 

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 ;)

nacho4d
i really want to know ,whether i could add something else into an API's class.i hope so.thank you
ben
Could you b more specific on what u want to add?
nacho4d
i want insert a UIProcess between the thumb and the track of UISlider.
ben
I just updated my answer regarding UIProcessView ;)
nacho4d
+1  A: 

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.

drawnonward
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
you mean isKindOfClass:.
tc.
@tc Thanks, I always mix those up.
drawnonward
A: 
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

ben