Repository: flutter
Issue: [video_player] Feature request: Switch to PlatformView on iOS (and macOS when possible) to fix performance issues
Labels: p: video_player,package,c: proposal,team-ecosystem,P3,triaged-ecosystem

## Use case

Since last fall I'm having performance issues with Flutter and from my investigation this seems to be all related to the Texture widget. In short, there seems to be a bug that causes the raster thread to block. This is especially true on older iOS devices (ex: iPhone 4s, iPad 2) since this is completely freezing my devices when using the video_player plugin. I've previously made a [bug report here](https://github.com/flutter/flutter/issues/78507)

Also, I'm mentioning this since this is related to the Texture widget and this feature request, I previously modified the video_player to add macOS and also tried the version from @cbenhagen which can be found [here](https://github.com/flutter/plugins/pull/3712) and I'm not completely having a smooth playback. I mean, some frame "jump" or stutter (like if the texture sent wasn't completely synced with the display link). This is more clearly seen when playing videos which the content consists of very slow linear movements (ex: like slowly sliding a static image).

Since macOS doesn't currently have a PlatformView widget, this feature request is mainly for iOS at the moment, but I think this should also be considered for the macOS video_player plugin.

## Proposal

To fix my problem on iOS, I have now modified the video_player plugins to use a PlatformView widget instead of the Texture widget. This has now made my application working great and even better than before (when I was able to use the video_player plugin as is some months ago).

By better I mean:

- The playback is smooth
- Scrolling/seeking is a lot smoother than with the display link (I was having problems where frames were not updated sometimes when scrolling, so not the right frame always appeared before playing)
- It doesn't make my old devices freeze, but are working great now

Therefore, I think the video_player plugin should switch to use the PlatformView widget (UiKitView) on iOS (and macOS) instead of the Texture widget.

Another benefit, this should also make it possible to play DRM protected videos.

## Solution

To give you something to play and test, you can find my modified iOS version of the video_player plugins (as of today 2021-07-17) there: https://github.com/guibarrette/flutter_plugins/tree/master/packages/video_player/video_player

[Link to the changes that I made (diff)](https://github.com/guibarrette/flutter_plugins/commit/887fa63ecf366a5fdff629824c0be108372e2ba8)

~This is not a completely clean solution since I didn't remove the display link from the iOS source code, but it is always paused and the video is displayed using the AVPlayerLayer. Therefore, this is now published as a proof of concept, but I can have a look to clean this if there is any interest to merge it with the main plugin repository.~ A [cleanup](https://github.com/guibarrette/flutter_plugins/commit/6badd303d62c9b204c33907ae6c1220d7e0b5721) as now been made (See my [post below](https://github.com/flutter/flutter/issues/86613#issuecomment-882116570) for more information and testing)

## P.S.

I looked at the Flutter and the Flutter Engine source code to see if I can find a solution to the Texture class, but I didn't find what could cause the problem at the moment. So, if anyone has any idea, that would be very welcome :)

Thanks!