prepareRouteSelectionForPlayback(completionHandler:)
Prepares the route selection for long-form video playback.
Declaration
func prepareRouteSelectionForPlayback(completionHandler: @escaping @Sendable (Bool, AVAudioSession.RouteSelection) -> Void)func prepareRouteSelectionForPlayback() async -> (Bool, AVAudioSession.RouteSelection)Parameters
- completionHandler:
A completion handler called after the system finishes preparing the playback route. The system passes the completion handler the following parameters:
shouldStartPlaybackA Boolean value that indicates whether playback should start.
routeSelectionA route selection value that indicates the active playback route.
Discussion
When playing long-form video content, call this method to indicate that playback is about to begin. Doing so provides the system the opportunity to prompt the user for an output destination, if needed, and perform any required routing.
The system only prompts the user to select a route if you’ve configured the audio session with a long-form video route-sharing policy. After the system configures the needed routing, it calls its completion handler, from which you can begin playback.
let session = AVAudioSession.sharedInstance()
session.prepareRouteSelectionForPlayback { shouldStartPlayback, routeSelection in
if shouldStartPlayback {
// Prepare and present player.
}
}