Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

@ditman
Copy link
Member

@ditman ditman commented Jul 14, 2022

Videos that report Infinity duration 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 Infinity duration value gracefully by using isFinite instead of !isNaN when deciding what to do with it.

(In Dart, a number can be only one of: isFinite, isNaN, isInfinite, so double.infinity.isNaN returns false!)

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a 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:

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

@ditman
Copy link
Member Author

ditman commented Jul 18, 2022

Very good catch, I thought I remember a magic number for "infinity" length, but I ended up not using it.

-9223372036854775807 is kinda an unfortunate value in JavaScript, because it's much smaller than JS' Number.MIN_SAFE_INTEGER (-9007199254740991).

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

let magic = -9223372036854775807
->          -9223372036854776000

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

@ditman
Copy link
Member Author

ditman commented Jul 18, 2022

Son of a...

../lib/src/video_player.dart:39:18: Error: The integer literal 9223372036854775807 can't be represented exactly in JavaScript.
Try changing the literal to something that can be represented in Javascript. In Javascript 9223372036854775808 is the nearest value that can be
represented exactly.
  milliseconds: -9223372036854775807,
                 ^^^^^^^^^^^^^^^^^^^

@ditman
Copy link
Member Author

ditman commented Jul 18, 2022

Dart nagged about me using -9223372036854775807 as a value, and asked me to use -9223372036854775808 which kind of defeat the purpose of having a "magic number" that is different across platforms :/

Anyway PTAL @stuartmorgan, other than standardizing the "live" duration across the whole plugin, it seems we're running out of options here :)

@ditman ditman force-pushed the infinite-videos-web branch from 6832aeb to 38fda56 Compare July 18, 2022 22:46
@ditman ditman requested a review from stuartmorgan-g July 18, 2022 22:46
@stuartmorgan-g
Copy link
Contributor

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.

@ditman
Copy link
Member Author

ditman commented Jul 19, 2022

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 androidx.media2.common.SessionPlayer.UNKNOWN_TIME). From their commit message:

- Use a single constant for unset/unknown times across
  all time bases. Note also that this moves away from
  use of -1 for unset/unknown times in ms, which was a
  bad choice (it might conflict with real times, such
  as a time representing being just behind the start
  of a live window).

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

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.

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

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a 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.

@ditman ditman requested a review from stuartmorgan-g July 20, 2022 01:21
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ditman ditman added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 20, 2022
@auto-submit auto-submit bot merged commit c16623d into flutter:main Jul 20, 2022
@ditman ditman deleted the infinite-videos-web branch July 28, 2022 17:06
yutaaraki-toydium pushed a commit to yutaaraki-toydium/plugins that referenced this pull request Aug 12, 2022
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: video_player platform-web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue when trying to play certain .webm videos from a network source

2 participants