Skip to content

Commit

Permalink
Merge pull request #195 from bitmovin/feature/swift-6-support
Browse files Browse the repository at this point in the history
Handle player view main actor isolation
  • Loading branch information
hawk23 authored Nov 26, 2024
2 parents def9d32 + 0a64b44 commit 079424c
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions ios/Classes/FlutterPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ internal class FlutterPlayerView: NSObject, FlutterPlatformView {
methodChannel.setMethodCallHandler(handleMethodCall)
eventChannel.setStreamHandler(self)
PlayerManager.shared.onPlayerCreated(id: arguments.playerId) { [weak self] player in
self?.createPlayerView(
player: player,
hasFullscreenHandler: arguments.hasFullscreenHandler,
isFullscreen: arguments.isFullscreen,
playerViewConfig: arguments.playerViewConfig.toNative()
)
Task { @MainActor [weak self] in
self?.createPlayerView(
player: player,
hasFullscreenHandler: arguments.hasFullscreenHandler,
isFullscreen: arguments.isFullscreen,
playerViewConfig: arguments.playerViewConfig.toNative()
)
}
}
}

Expand All @@ -59,17 +61,22 @@ internal class FlutterPlayerView: NSObject, FlutterPlatformView {
extension FlutterPlayerView: FlutterStreamHandler {
func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
self.eventSink = events
playerView?.add(listener: self)
Task { @MainActor in
playerView?.add(listener: self)
}
return nil
}

func onCancel(withArguments arguments: Any?) -> FlutterError? {
playerView?.remove(listener: self)
self.eventSink = nil
Task { @MainActor in
playerView?.remove(listener: self)
}
return nil
}
}

@MainActor
private extension FlutterPlayerView {
func handleMethodCall(call: FlutterMethodCall, result: @escaping FlutterResult) {
do {
Expand Down

0 comments on commit 079424c

Please sign in to comment.