码迷,mamicode.com
首页 > 移动开发 > 详细

ios get airplay name

时间:2015-07-15 12:42:59      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

tarting from iOS7 AudioToolbox API for currentRoute becomes deprecated:

Apple instead made currentRoute API available to you in AudioSession, which allows retrieving it‘s port information as well as listening to audioRouteChangeNotification in a nice way:

NSString* airplayName = [self activeAirplayOutputRouteName];
if (airplayName) {
    //airplay is active

}

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioRouteHasChangedNotification:) name:AVAudioSessionRouteChangeNotification object:[AVAudioSession sharedInstance]];
 1 - (NSString*)activeAirplayOutputRouteName
 2 {
 3     AVAudioSession* audioSession = [AVAudioSession sharedInstance];
 4     AVAudioSessionRouteDescription* currentRoute = audioSession.currentRoute;
 5     for (AVAudioSessionPortDescription* outputPort in currentRoute.outputs){
 6         if ([outputPort.portType isEqualToString:AVAudioSessionPortAirPlay])
 7             return outputPort.portName;
 8     }
 9 
10     return nil;
11 }
12 
13 - (void)audioRouteHasChangedNotification:(NSNotification*)notification
14 {
15     //do something
16 }

 

ios get airplay name

标签:

原文地址:http://www.cnblogs.com/XCoderLiu/p/4647887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!