Jakub Turek 3e8b8130cd [video_player] Fix iOS crash with multiple players (#4202)
This PR fixes crash in `video_player` package on iOS. 

https://github.com/flutter/flutter/issues/124937

### Detailed description

I can observe the crash when displaying a couple of the different players (different URLs) inside a `ListView`. The crash happens inside of `AVFoundation` framework:

```objc
[AVPlayer _createAndConfigureFigPlayerWithType:completionHandler:]
```

In order to debug the issue, I ran the application using the plugin with `Zombie Objects` inspection turned on. The `Zombie Objects` reports the following issue:

```
*** -[FLTVideoPlayer retainWeakReference]: message sent to deallocated instance 0x6030009b2e10
```

This, in conjunction with the `NSKeyValueWillChange` line present in the stack trace led me to believe, that culprit is sending a KVO notification to the `FLTVideoPlayer` instance that's deallocated.

Next, I examined the plugin code and identified one property that doesn't have the KVO removed. In `addObserversForItem:player:` method in `FLTVideoPlayerPlugin.m`:

```
  [player addObserver:self
           forKeyPath:@"rate"
              options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
              context:rateContext];
```

The observer for `@"rate"` is never cleaned up. To be entirely sure that the issue comes from KVO that's not cleaned up, I've added the following class:

```
@implementation EmptyObserver

- (void)observeValueForKeyPath:(NSString *)path
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context {}

@end
```

and registered the observation as follows (notice that `EmptyObserver` is never retained and deallocated instantly):

```
  [player addObserver:[[EmptyObserver alloc] init]
           forKeyPath:@"rate"
              options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
              context:rateContext];
```

The exception I got seems to be matching the underlying issue:

```
*** -[EmptyObserver retainWeakReference]: message sent to deallocated instance 0x6020001ceb70
```

This means the fix for the issue is to add the following to `disposeSansEventChannel` method:

```
[self.player removeObserver:self forKeyPath:@"rate"];
```

After applying the patch, I can no longer crash the player.
2023-07-18 12:50:49 +00:00
2017-08-01 14:58:30 -07:00

Flutter Packages

Build Status Release Status OpenSSF Scorecard

This repo is a companion repo to the main flutter repo. It contains the source code for Flutter's first-party packages (i.e., packages developed by the core Flutter team). Check the packages directory to see all packages.

These packages are also available on pub.

Issues

Please file any issues, bugs, or feature requests in the main flutter repo. Issues pertaining to this repository are labeled "package".

Contributing

If you wish to contribute a new package to the Flutter ecosystem, please see the documentation for developing packages. You can store your package source code in any GitHub repository (the present repo is only intended for packages developed by the core Flutter team). Once your package is ready you can publish to the pub repository.

If you wish to contribute a change to any of the existing packages in this repo, please review our contribution guide, and send a pull request.

Packages

These are the packages hosted in this repository:

Package Pub Points Popularity Issues Pull requests
animations pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
camera pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
cross_file pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
css_colors pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
cupertino_icons pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
espresso pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
extension_google_sign_in_as_googleapis_auth pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
file_selector pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
flutter_adaptive_scaffold pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
flutter_image pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
flutter_lints pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
flutter_markdown pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
flutter_plugin_android_lifecycle pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
flutter_template_images pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
go_router pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
go_router_builder pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
google_maps_flutter pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
google_sign_in pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
image_picker pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
in_app_purchase pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
ios_platform_images pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
local_auth pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
metrics_center pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
multicast_dns pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
palette_generator pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
path_provider pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
pigeon pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
pointer_interceptor pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
plugin_platform_interface pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
quick_actions pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
rfw pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
shared_preferences pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
standard_message_codec pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
url_launcher pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
video_player pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
web_benchmarks pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
webview_flutter pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
xdg_directories pub package pub points popularity GitHub issues by-label GitHub pull requests by-label
Description
A collection of useful packages maintained by the Flutter team
Readme BSD-3-Clause 435 MiB
Languages
Dart 61.3%
Java 10.1%
C++ 9.8%
Swift 5.9%
Objective-C 5.3%
Other 7.4%