Hello, just turned "Complete" concurrency check in xcode 14.3 and am trying to figure out if there's a way to have AVFoundations types (like AVAsyncProperty, AVPlayerItem, etc) returned from async functions inside a View .task {} without 'Non-sendable' warnings.
Or, conversely, to pass the AVQueuePlayer instance to that function to avoid passing around AVAsset/PlayerItem/Etc.
struct ContentView: View {
@State var player = AVQueuePlayer()
private var trackLoader = TrackLoader()
var body: some View {
VideoPlayer(player: player)
.task {
let playerItem = await trackLoader.loadAsyncProperties()
player.insert(playerItem)
/// OR
await trackLoader.loadAsyncPropertiesAndInsertPlayerItem(player: player)
}
}
}
actor trackLoader {
nonisolated func loadAsyncProperties () async -> AVPlayerItem {
/// load asset tracks, timerange, etc
// return AVPlayerItem
}
@MainActor func loadAsyncPropertiesAndInsertPlayerItem (player: AVQueuePlayer) async {
/// load asset tracks, timerange, etc, await(s) marked 'non-sendable'
// player.insert()
}
}