IOS: MPVolumeView game collector

I use MPVolumeView to select a device to play in playback mode in playback mode. Is there any possible alternative for a non-standard API for this, so I could provide my own user interface controls to select the device to broadcast?

When referring to the API, I mean that all I need is:

  • The ability to redirect sound to an audio resource specific to playback in playback mode.
  • Return the device names for playback. (get all available audio clips, and then get descriptions for playing audio clips).

I know that AudioToolbox provides an additional API for working with AudioSession, but the only way I found to redirect audio is AVAudioSession:

- (BOOL)overrideOutputAudioPort:(AVAudioSessionPortOverride)portOverride  error:(NSError **)outError`

which only allows you to redirect the sound to the built-in speakers. Maybe there is some other way how to achieve it? (I also found a way to get the name AirplayDevice as a description of currentAudioRoute - Get the name of an AirPlay device using AVPlayer )

+4
source share
1 answer

The exact answer to my question is:

(i) It is not possible to switch audio resources programmatically using the open API, except switching to the built-in speakers.

[[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil];

(ii) Airplay-, AudioRoute. AirPlay AVPlayer

, :

MPVolumeView, volumeSlider routeButton. airplayDevice Apple (airPlay, bluetooth ..) UIActionSheet, , routeButton, , audioRouteChangeNotification:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioRouteHasChangedNotification:) name:AVAudioSessionRouteChangeNotification object:[AVAudioSession sharedInstance]];

( , / , )

, API:

MPMediaPlayer framework 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: airplayRoute)

+6

Source: https://habr.com/ru/post/1536063/


All Articles