Non-sendable type AVMediaSelectionGroup

Hi all, we try migrate project to Swift 6 Project use AVPlayer in MainActor Selection audio and subtitiles not work Task { @MainActor in let group = try await item.asset.loadMediaSelectionGroup(for: AVMediaCharacteristic.audible) get error: Non-sendable type 'AVMediaSelectionGroup?' returned by implicitly asynchronous call to nonisolated function cannot cross actor boundary

and second example `if #available(iOS 15.0, *) { player?.currentItem?.asset.loadMediaSelectionGroup(for: AVMediaCharacteristic.audible, completionHandler: { group, error in if error != nil { return }

            if let groupWrp = group {
                DispatchQueue.main.async {
                    self.setupAudio(groupWrp, audio: audioLang)
                }
            }
        })
    }`

get error: Sending 'groupWrp' risks causing data races

Hello @Rastrelli, thank you for your post. One workaround is to annotate your import AVFoundation statement with @preconcurrency:

@preconcurrency import AVFoundation

This clears the warning and allows you to build, but you should then make sure that your player item is thread-safe.

Non-sendable type AVMediaSelectionGroup
 
 
Q