Question

I made an app which provides you to listen to a streamed radio. I don't know how it's possible to integrate AirPlay in my app?

This is the code to let it play:

-(IBAction)play {
        if(clicked == 0) {
            clicked = 1;
            NSURL *url = [NSURL URLWithString:@"http://stream.domain.com/high.mp3"];
            audioPlayer = [[AVPlayer alloc] initWithURL:url];
            [audioPlayer play];
            [start setTitle:@"Stop" forState:UIControlStateNormal];
        }
        else {
            [audioPlayer pause];
            clicked = 0;
            [start setTitle:@"Start" forState:UIControlStateNormal];
        }
    }

What do I need to add to let AirPlay share this?

Was it helpful?

Solution

As @shabzo mentioned, [audioPlayer setAllowsAirPlayVideo:YES], however, as over iOS 5, this is the default.

You may want to set "Required background modes" in the project plist, to "App plays audio"

In order to get the airplay routes button, you'll need to add MPVolumeView. This will show the airplay button, if devices are available on the network. You should be able to hide the volume button if all you want is the route button.

You may also be interested in setting the [MPNowPlayingInfoCenter defaultCenter], to ensure the track info and album art makes it to the playing device (AppleTV).

OTHER TIPS

To enable Airplay for AVPlayer simply add this line of code:

[audioPlayer setAllowsAirPlayVideo:YES];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top