Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[video_player] Feature request: Switch to PlatformView on iOS (and macOS when possible) to fix performance issues #86613

@guibarrette

Description

@guibarrette

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

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 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)

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 as now been made (See my post below 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: proposalA detailed proposal for a change to Flutterp: video_playerThe Video Player pluginpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions