所以准确回答我的问题:
(I)它无法切换音频使用公共API以编程方式传输,除了切换到内置扬声器。
[[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil];
(II)你可以,如果是主动AudioRoute只检索AirPlay的设备的名称。 Get name of AirPlay device using AVPlayer
所以实用的解决方案来呈现定制UI控件,以便选择点播将是:
要定制MPVolumeView
,在那里你可以禁用volumeSlider
和定制routeButton
。然而,当您点击routeButton
时弹出窗口,但您可以观察用户何时将通过订阅audioRouteChangeNotification进行选择,您没有其他选择在UIActionSheet
中选择与Apple兼容的无线设备(airPlay,蓝牙等)列表中的airplayDevice选项:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioRouteHasChangedNotification:) name:AVAudioSessionRouteChangeNotification object:[AVAudioSession sharedInstance]];
(也请注意,如果您将插入/拔出耳机,它也将触发此通知),如果你有兴趣如何检索所有可用audioRoutes与私有API编程切换
:
MPMediaPlayer
框架包含一个私有类MPAVRoutingController
,它允许你正是:
Class MPAVRoutingController = NSClassFromString(@"MPAVRoutingController");
Class MPAVRoute = NSClassFromString(@"MPAVRoute");
id routingController = [[MPAVRoutingController alloc] init];
NSArray* availableRoutes = [routingController performSelector:@selector(availableRoutes)];
BOOL isSwitchSuccesful = [[routingController performSelector:@selector(pickRoute:) withObject:availableRoutes.lastObject] boolValue];
(如果你想然后访问audioRoute信息,并检查它是否是的Airplay:Detecting airplayRoute)
我的[类似的问题](HTTP://计算器。com/questions/31864398/ios-airplay-action-sheet-for-public-app-store-publishing-like-in-spotify),并想知道如果不使用私有API,即使没有定制的常规操作表也是可能的? –
我不知道他们是否添加了任何新的API,但似乎我们无法直接使用他们的ActionSheet(现在称为AlertController)。你可以尝试使用它 - 比如尝试访问它的视图子视图,并尝试sendActionsForControlEvents,看看你是否可以通过编程方式假冒用户触摸,如果你可以,那么你可能可能会在没有私有API的情况下以编程方式切换路由 – ambientlight