MPVolumeView AirPlay button not showing up

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:

It may be that you're placing your VolumeView against a white background. The Airplay route button is white before it's used (i.e.: when it's not routing via AirPlay), so if you put the control against a white background, you won't see it but it'll respond to taps. Change the background to something like red, as above, and it shows.

Need Your Help

Count redirects

php mysql redirect count

I found a redirect script, and I've been trying to get it to count the redirects (url_hits). Can't get it to work and I was wondering if someone out there could help me.

Writing access to private objects via public readOnly property

c# properties encapsulation readonly

I am currently struggling to understand something i just saw somewhere.