-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[video_player] Avoid blocking the main thread loading video count #4714
Conversation
FLTVideoPlayerPlugin *videoPlayerPlugin = | ||
(FLTVideoPlayerPlugin *)[[FLTVideoPlayerPlugin alloc] initWithRegistrar:registrar]; | ||
|
||
NSDictionary<NSString *, id> *audioInitialization = [self testPlugin:videoPlayerPlugin uri:@"https://cdn.pixabay.com/audio/2021/09/06/audio_bacd4d6020.mp3"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update this to https://flutter.github.io/assets-for-api-docs/assets/videos/rooster.mp3
once flutter/assets-for-api-docs#177 merges. Will also update the duration integer assert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a separate repo instead of landing the mp3 here and using a raw GitHub URL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking binaries into git repos is generally frowned upon since it never gets removed from the git history. I think assets-for-api-doc
is the side-repo other flutter
org repos use to localize the sin to one place.
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4', |
plugins/packages/video_player/video_player_web/example/integration_test/video_player_web_test.dart
Line 27 in 7686be7
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4', |
We can host them somewhere else, but we should host the videos and images all together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[asset loadValuesAsynchronouslyForKeys:@[ @"tracks" ] completionHandler:^{ | ||
if ([asset statusOfValueForKey:@"tracks" error:nil] != AVKeyValueStatusLoaded) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See similar logic at
plugins/packages/video_player/video_player/ios/Classes/FLTVideoPlayerPlugin.m
Lines 220 to 221 in 411f09e
if ([asset statusOfValueForKey:@"tracks" error:nil] == AVKeyValueStatusLoaded) { | |
NSArray *tracks = [asset tracksWithMediaType:AVMediaTypeVideo]; |
[asset loadValuesAsynchronouslyForKeys:@[ @"tracks" ] completionHandler:assetCompletionHandler]; |
packages/video_player/video_player/ios/Classes/FLTVideoPlayerPlugin.m
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jmagman ! I think we should do more checks with threads in the future, contributors (including me) can accidently break the thread model or cause the main thread blocked easily.
#4639 introduced playing mp3 files with
video_player
. The method that checks if the player is ready needs to handle zero-sized audio files, so it called[AVAsset tracksWithMediaType:AVMediaTypeVideo]
on the main thread. However, if the tracks aren't loaded, that API will synchronously load them. Docs say: "Becomes callable without blocking when the key @"tracks" has been loaded". This caused the UI to become unresponsive until the video loads.Instead, check that the tracks are loaded, and if not, load them, then re-schedule the call to make sure the player is ready.
Unfortunately the
loadTracksWithMediaType:completionHandler:
we really want only became available on iOS 15.Added more tests for controlling both audio and video media types.
Fixes flutter/flutter#97356
Blocked by test audio file PR flutter/assets-for-api-docs#177
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.