I originally added an MPVolumeView dynamically on to a page...
#import "MediaPlayer/MPVolumeView.h"
.
.
-(IBAction) handleVolumeButtonClicked:(id) sender {
if (volumeView == nil) {
volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(25, 378, 270, 30)];
[self.view addSubview:volumeView];
[volumeView release];
} else {
[volumeView removeFromSuperview];
volumeView = nil;
}
}
But for some reason I started getting reports of the application crashing when dynamically adding the volume component.
To work around this, I decided to try and add the component to the view via the XCode designer, but then I realised that I didn't know how to do this!
I dragged an 'Object' from the template to the Object palette first, but then I found that I couldn't add it to the view. So I scrapped that idea and then dragged the 'View' object directly on to the .xib view.
Once the component was added, I tried to change the 'Custom Class' to 'MPVolumeView', but the view just rendered an empty rectangle. Running the code in the simulator failed to render anything.
Does anyone know what steps I am missing to add a class to the view that doesnt already exist in the palette?
Adding a generic UIView and setting the custom class to MPVolumeView does indeed work. Make sure to do the following:
Not sure if you have figured this out by now. I just created an app with a volume slider successfully. Here's what I did (from MPVolumeView):
MPVolumeView
Hope it helps.
You should try running your app on an iOS device, not the simulator. On the simulator the MPVolumeView displays "No Volume Available" in white text. If the view's background color is set to white (default in Interface Builder) then the view appears to be empty.
Found another solution.
Even much simpler:
Add a view and change the Class to MPVolumeView and declare in .h
In .m just allocate it.