Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle player view main actor isolation #195

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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