Reputation: 621
We are building an iOS app where users can watch videos under a subscription model.
We don't want users to Airplay the videos to any other device.
The video is being played inside a UIWebView.
I checked various online resources:
The above options have not worked.
Also, i tried this code but it always return 1.
if ([[UIScreen screens] count] < 2)) {
//streaming
}
else {
//mirroring
}
I have tried this code as well:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveAirPlayNotification:) name: UIScreenDidConnectNotification object:nil];
This notification system works only when i launch the App and then turn on Airplay. If i turn on Airplay and then launch the App, then nothing is detected.
I need to detect if mirroring is on when the app launches. I have seen other apps do this so i am sure this is possible.
Please help.
Upvotes: 5
Views: 2297
Reputation: 764
Try this solution.
- (BOOL)isAirplayOn
{
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
AVAudioSessionRouteDescription* currentRoute = audioSession.currentRoute;
for (AVAudioSessionPortDescription* outputPort in currentRoute.outputs){
if ([outputPort.portType isEqualToString:AVAudioSessionPortAirPlay])
return YES;
}
return NO;
}
Upvotes: 5