Using MPVolumeView
I wanted to create an AirPlay output button for the app's audio.
MPVolumeView *volumeView = [ [MPVolumeView alloc] initWithFrame:CGRectMake(20, 20, 220, 20)];
[volumeView setShowsVolumeSlider:NO];
[volumeView setShowsRouteButton:YES];
[volumeView sizeToFit];
[self.view addSubview:volumeView];
[volumeView release];
Errors / issues none but it doesn't show up, any ideas?
Thanks!
instead of init, send it initWithFrame:(CGRect) message. It seems like the view is there, it just has a frame of (0,0,0,0)
Here's the code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ViewController *vc = [[ViewController alloc] init];
[vc.view setBackgroundColor:[UIColor redColor]];
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(20, 20, 200, 50)];
[volumeView setShowsVolumeSlider:YES];
[volumeView setShowsRouteButton:YES];
[volumeView sizeToFit];
[vc.view addSubview:volumeView];
UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, 200, 50)];
testLabel.text = @"TESTING";
[vc.view addSubview:testLabel];
[self.window setRootViewController:vc];
[self.window makeKeyAndVisible];
[vc viewDidLoad];
return YES;
}
It works when testing on device: