-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[video_player_web] Improve handling of "Infinite" videos. #6101
Conversation
stuartmorgan-g
left a comment
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.
How do videos actually behave with this fix? From a quick look at the app-facing code it looks like we don't actually expect duration to be zero for an initialized video, so I would expect that things like the progress indicator, seeking, etc. would all be at least somewhat broken. In fact, it looks like the progress indicator control would throw a div-zero.
We should probably match the (very unfortunate IMO, but the ship has sailed) precedent of using the magic Android value:
plugins/packages/video_player/video_player_avfoundation/ios/Classes/FLTVideoPlayerPlugin.m
Lines 114 to 119 in a9d2381
| const int64_t TIME_UNSET = -9223372036854775807; | |
| NS_INLINE int64_t FLTCMTimeToMillis(CMTime time) { | |
| // When CMTIME_IS_INDEFINITE return a value that matches TIME_UNSET from ExoPlayer2 on Android. | |
| // Fixes https://github.com/flutter/flutter/issues/48670 | |
| if (CMTIME_IS_INDEFINITE(time)) return TIME_UNSET; |
Eventually I think we should clean things up so that there's a clear plugin-defined way of expressing infinite duration, and we plumb that throughout the stack, but in the mean time having web match Android and iOS's current magic-value version of that is probably the most compatible option. (E.g., if we add handling of the magic value in the progress indicator code, or if plugin clients are already special casing that magic value, then it will Just Work for web too).
|
Very good catch, I thought I remember a magic number for "infinity" length, but I ended up not using it.
Anyway, I tested it in Safari 13 on an iPhone simulator (which is the latest modern browser without BigInt support), and it is still a ridiculously small number (even though there's some wrapping): Close! And since we're not doing math with the value (only using it as a boundary), it's probably fine. I'll return the magic value instead, matching the other platforms (yikes!) |
|
Son of a... |
|
Dart nagged about me using Anyway PTAL @stuartmorgan, other than standardizing the "live" duration across the whole plugin, it seems we're running out of options here :) |
6832aeb to
38fda56
Compare
|
It seems like the next best option is to decide on our own standard and have web be the first to adopt it, and then we can do a breaking change at some later point to move the other platforms over to it. Your point about a threshold is a good one. Maybe we should just make -1 be our new target standard for representing this at the platform interface layer? I assume there are no legitimate cases of negative durations. |
I thought about -1 as well, but then decided to do a blame on the current value of TIME_UNSET to understand why exoplayer had settled in such a "wacky" value (other than maybe matching If we follow the same trick that ExoPlayer2 used to come up with their value, but that works fine in JavaScript: JS_COMPATIBLE_TIME_UNSET = Number.MIN_SAFE_INTEGER + 1; // -9007199254740990 The number is several orders of magnitude larger than the current one, but if when converted from milliseconds to years it is still over 285000 (sounds long enough for any pre-roll!)
I'll use that, and create an issue to standardize the value across the different implementations, and the flutter-provided UX and logic of our Player (which seems to always assume that the duration of a video is always finite!) |
stuartmorgan-g
left a comment
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.
Nice investigation on the constant! This looks like a good approach.
packages/video_player/video_player_web/lib/src/video_player.dart
Outdated
Show resolved
Hide resolved
stuartmorgan-g
left a comment
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!
Videos that report
Infinityduration are breaking the initialization event of the video player on the web.This PR modifies the function that prepares the init event, to handle the
Infinityduration value gracefully by usingisFiniteinstead of!isNaNwhen deciding what to do with it.(In Dart, a number can be only one of:
isFinite,isNaN,isInfinite, sodouble.infinity.isNaNreturns false!)Pre-launch Checklist
dart format.)[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.mdto 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.