-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[video_player] foundation - reduce seek accuracy to fix seek to end bug #3784
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
[video_player] foundation - reduce seek accuracy to fix seek to end bug #3784
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
Having a hard time writing tests that fail with the old code... |
packages/video_player/video_player/example/integration_test/video_player_test.dart
Outdated
Show resolved
Hide resolved
packages/video_player/video_player_avfoundation/ios/Classes/FLTVideoPlayerPlugin.m
Outdated
Show resolved
Hide resolved
packages/video_player/video_player_avfoundation/ios/Classes/FLTVideoPlayerPlugin.m
Outdated
Show resolved
Hide resolved
packages/video_player/video_player_avfoundation/ios/Classes/FLTVideoPlayerPlugin.m
Outdated
Show resolved
Hide resolved
b6c7651
to
041dcb3
Compare
// Without adding tolerance when seeking to duration, | ||
// seekToTime will never complete, and this call will hang. | ||
// see issue https://github.com/flutter/flutter/issues/124475. | ||
CMTime tolerance = location == duration ? CMTimeMake(1, 1000) : kCMTimeZero; |
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.
Can you write a unit test (XCTest) for this behavior?
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 have no idea what I didn't think of that when @tarrinneal and I were talking about testing for this 🤦🏻
It looks like we don't currently have a way to mock out the underlying AVPlayer
, which significantly reduces testability. I would suggest wrapping the current call to [AVPlayer playerWithPlayerItem:]
in a factory object, and do DI of that factory. So you'd make a test-only header that declared:
- A protocol for the
AVPlayer
instance factory (which it looks like would just be a single method) - A new init that takes an instance of the factory protocol.
The, similar to the other DI you did recently, you'd have a private implementation of that protocol that's the default version, just wrapping [AVPlayer playerWithPlayerItem:]
, but tests could replace it with something vending mock AVPlayer instances where you could validate the tolerance parameter.
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.
Can also try stubbing the constructor directly if it's easier:
id mockPlayer = OCMClassMock([AVPlayer class]);
OCMStub([AVPlayer playerWithPlayerItem:OCMOCM_ANY]).andReturn(mockPlayer);
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.
Please don't. OCMock class mocking is giant foot-gun; it's incredibly easy to accidentally leak mocking across tests.
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.
gotcha. i did that a few times for camera plugin iirc. i should clean that up sometime.
@stuartmorgan Tests are written, I'm certain the objc code can be better. So I'd love to get some thorough feedback, if you have time. |
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.
LGTM with nits
packages/video_player/video_player_avfoundation/ios/Classes/FLTVideoPlayerPlugin_Test.h
Outdated
Show resolved
Hide resolved
packages/video_player/video_player_avfoundation/ios/Classes/FLTVideoPlayerPlugin_Test.h
Outdated
Show resolved
Hide resolved
packages/video_player/video_player_avfoundation/example/ios/RunnerTests/VideoPlayerTests.m
Outdated
Show resolved
Hide resolved
packages/video_player/video_player_avfoundation/example/ios/RunnerTests/VideoPlayerTests.m
Outdated
Show resolved
Hide resolved
packages/video_player/video_player_avfoundation/example/ios/RunnerTests/VideoPlayerTests.m
Show resolved
Hide resolved
packages/video_player/video_player_avfoundation/example/ios/RunnerTests/VideoPlayerTests.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.
LGTM
auto label is removed for flutter/packages, pr: 3784, due to - The status or check suite repo_checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
flutter/packages@6328cfb...6608b60 2023-05-15 [email protected] [ci] Remove unnecessary Linux libraries (flutter/packages#3975) 2023-05-15 [email protected] [ci] Enforce a minimum Kotlin version in examples (flutter/packages#3979) 2023-05-15 [email protected] [ci] Disable Windows repo tool tests (flutter/packages#3980) 2023-05-12 [email protected] [ci] Add LUCI repo tool tests (flutter/packages#3964) 2023-05-12 [email protected] [url_launcher] Set broadcast reciever visability as required by target api 34 (flutter/packages#3973) 2023-05-12 [email protected] Update build.gradle with a comment explaining version (flutter/packages#3972) 2023-05-12 [email protected] Roll Flutter from 8c5a1ea to a76dbe4 (12 revisions) (flutter/packages#3958) 2023-05-12 [email protected] [image_picker] Fix Android lints (flutter/packages#3887) 2023-05-12 [email protected] [various] Update minimum Flutter version to 3.3 (flutter/packages#3967) 2023-05-12 [email protected] [tool] Target specific Android unit tests (flutter/packages#3955) 2023-05-12 [email protected] [camerax] Add a dependency on kotlin-bom to align versions of kotlin-stdlib (flutter/packages#3960) 2023-05-12 [email protected] [local_auth] Improve iOS test DI (flutter/packages#3959) 2023-05-12 [email protected] [ci] Ensure scripts fail if a command fails (flutter/packages#3963) 2023-05-11 [email protected] [ci] Pin the Flutter version for `release` (flutter/packages#3965) 2023-05-11 [email protected] [video_player] foundation - reduce seek accuracy to fix seek to end bug (flutter/packages#3784) 2023-05-11 [email protected] [image_picker] Fix use_build_context_synchronously violations (flutter/packages#3969) 2023-05-11 [email protected] [tool] Ensure that publish credential path is available (flutter/packages#3970) 2023-05-11 [email protected] [go_router] change `fix_data.yaml` uris to be absolute to fix lints (flutter/packages#3877) 2023-05-11 [email protected] [tool] Use new pub cache location for publish (flutter/packages#3962) 2023-05-10 [email protected] Roll Flutter (stable) from f72efea to 84a1e90 (1920 revisions) (flutter/packages#3961) 2023-05-10 [email protected] [image_picker_android] Improved Bitmap resize on Android (flutter/packages#3423) 2023-05-10 [email protected] [camerax] Add Kotlin duplicate classes known error to README.md (flutter/packages#3957) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@6328cfb...6608b60 2023-05-15 [email protected] [ci] Remove unnecessary Linux libraries (flutter/packages#3975) 2023-05-15 [email protected] [ci] Enforce a minimum Kotlin version in examples (flutter/packages#3979) 2023-05-15 [email protected] [ci] Disable Windows repo tool tests (flutter/packages#3980) 2023-05-12 [email protected] [ci] Add LUCI repo tool tests (flutter/packages#3964) 2023-05-12 [email protected] [url_launcher] Set broadcast reciever visability as required by target api 34 (flutter/packages#3973) 2023-05-12 [email protected] Update build.gradle with a comment explaining version (flutter/packages#3972) 2023-05-12 [email protected] Roll Flutter from 8c5a1ea to a76dbe4 (12 revisions) (flutter/packages#3958) 2023-05-12 [email protected] [image_picker] Fix Android lints (flutter/packages#3887) 2023-05-12 [email protected] [various] Update minimum Flutter version to 3.3 (flutter/packages#3967) 2023-05-12 [email protected] [tool] Target specific Android unit tests (flutter/packages#3955) 2023-05-12 [email protected] [camerax] Add a dependency on kotlin-bom to align versions of kotlin-stdlib (flutter/packages#3960) 2023-05-12 [email protected] [local_auth] Improve iOS test DI (flutter/packages#3959) 2023-05-12 [email protected] [ci] Ensure scripts fail if a command fails (flutter/packages#3963) 2023-05-11 [email protected] [ci] Pin the Flutter version for `release` (flutter/packages#3965) 2023-05-11 [email protected] [video_player] foundation - reduce seek accuracy to fix seek to end bug (flutter/packages#3784) 2023-05-11 [email protected] [image_picker] Fix use_build_context_synchronously violations (flutter/packages#3969) 2023-05-11 [email protected] [tool] Ensure that publish credential path is available (flutter/packages#3970) 2023-05-11 [email protected] [go_router] change `fix_data.yaml` uris to be absolute to fix lints (flutter/packages#3877) 2023-05-11 [email protected] [tool] Use new pub cache location for publish (flutter/packages#3962) 2023-05-10 [email protected] Roll Flutter (stable) from f72efea to 84a1e90 (1920 revisions) (flutter/packages#3961) 2023-05-10 [email protected] [image_picker_android] Improved Bitmap resize on Android (flutter/packages#3423) 2023-05-10 [email protected] [camerax] Add Kotlin duplicate classes known error to README.md (flutter/packages#3957) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…ug (flutter#3784) Reduces avplayer seek accuracy when seeking to end of video to fix `seekToTime` never running completion handler. fixes flutter/flutter#124475
CMTime locationCMT = CMTimeMake(location, 1000); | ||
CMTimeValue duration = _player.currentItem.asset.duration.value; | ||
// Without adding tolerance when seeking to duration, | ||
// seekToTime will never complete, and this call will hang. | ||
// see issue https://github.com/flutter/flutter/issues/124475. | ||
CMTime tolerance = location == duration ? CMTimeMake(1, 1000) : kCMTimeZero; |
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.
What if _player.currentItem.asset.duration.timescale
is not 1000? This comparison compares just numerators of fractions.
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.
Video https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4 from tests gives 2422 and 600 for _player.currentItem.asset.duration
value
and timescale
.
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.
@misos1 This is a PR that landed a year and a half ago; comments here aren't actionable. If there's a bug, please file an issue with details.
Reduces avplayer seek accuracy when seeking to end of video to fix
seekToTime
never running completion handler.fixes flutter/flutter#124475
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.