packages icon indicating copy to clipboard operation
packages copied to clipboard

[video_player] Add optional web options

Open defuncart opened this issue 1 year ago • 26 comments

  • Fixes https://github.com/flutter/flutter/issues/62192
  • Fixes first part of https://github.com/flutter/flutter/issues/88151 (ability to show controls)
  • Fixes https://github.com/flutter/flutter/issues/64397

Can be used as follows:

_controller = VideoPlayerController.asset(
  'assets/Butterfly-209.mp4',
  videoPlayerOptions: const VideoPlayerOptions(
    webOptions: VideoPlayerWebOptions(
        controls: VideoPlayerWebOptionsControls.enabled(
          allowDownload: false,
          allowFullscreen: false,
          allowPlaybackRate: false,
          allowPictureInPicture: false,
        ),
        allowContextMenu: false,
        allowRemotePlayback: false,
     ),
  ),
);
Bildschirmfoto 2023-07-06 um 17 04 59

Pre-launch Checklist

  • [X] I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • [X] I read the Tree Hygiene wiki page, which explains my responsibilities.
  • [X] I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • [X] I signed the CLA.
  • [X] The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • [X] 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.
  • [x] I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • [x] 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.
  • [x] All existing and new tests are passing.

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

defuncart avatar Feb 22 '23 16:02 defuncart

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.

flutter-dashboard[bot] avatar Feb 22 '23 16:02 flutter-dashboard[bot]

@ditman @stuartmorgan The original PR was opened 3 months ago, would be nice to get some feedback on the api. I think this is a feature that can benefit flutter web users.

defuncart avatar Feb 22 '23 16:02 defuncart

Bringing over my API note from the other PR for convenience (/cc @ditman)

I think the main question is whether we want to expose things through an options mechanism like this, or do something more direct like exposing the element for direct manipulation. How many more things like this might we want to add later? If we end up duplicating all of a large API surface that would be problematic, but if it's a fairly small set of options this (or the alternate pattern we have in some other plugins of using platform-specific option subclasses) could be reasonable.

stuartmorgan avatar Feb 22 '23 16:02 stuartmorgan

@ditman Do you have an opinion on the API question above?

stuartmorgan avatar Apr 04 '23 19:04 stuartmorgan

Update from triage: waiting for @ditman's input on the high-level API question.

stuartmorgan avatar May 16 '23 19:05 stuartmorgan

@ditman @stuartmorgan Thanks for the review.

As more options may come in the future (i.e. mute, autoplay), I'd split the control options out to their own model VideoPlayerWebOptionsControls for a clearer api with named constructors.

I agree that setWebOptions(options) should suffice for web users and it doesn't need to be a property of VideoPlayerOptions. However, the benefit of being part of VideoPlayerOptions is that when initialize is called, the optional web options are initialized. If setWebOptions(options) is a method on VideoPlayerController, then initialize will need to be invoked before setWebOptions.

defuncart avatar May 17 '23 09:05 defuncart

@ditman Do you want to weigh in again on the structure we want for exposing <video> attributes?

stuartmorgan avatar Jun 29 '23 18:06 stuartmorgan

@ditman Added allowPictureInPicture and allowRemotePlayback options. As picture-in-picture is displayed in controls list, I've added the option to VideoPlayerWebOptionsControls. If you are happy with the API, then I can add tests etc.

defuncart avatar Jul 07 '23 08:07 defuncart

If you are happy with the API, then I can add tests etc.

I'm happy with the API @defuncart, thanks! The only unaddressed concern is using dynamic as a return value of the _onContextMenu function definition, which should be more precise (at the very least it should be: Object?)

ditman avatar Jul 08 '23 05:07 ditman

@ditman Update function definition to be correct. Does 'override: no versioning needed' need to be added so that repo_checks can succeed?

defuncart avatar Jul 08 '23 08:07 defuncart

Does 'override: no versioning needed' need to be added so that repo_checks can succeed?

Which of the version change exemptions (see link in PR checklist) do you believe this PR falls under?

stuartmorgan avatar Jul 08 '23 13:07 stuartmorgan

@defuncart if we don't add a version to the platform_interface package, it won't get published to pub -> people won't be able to use the new methods that you're defining there. You'll have to split this PR into a couple of PRs so you can land the packages in logical order:

  1. platform_interface (defining the new methods and types), then
  2. all _platform implementations (defining the per-platform behavior), and finally
  3. core plugin package (using/giving access to new features to all programmers)

See "Changing Federated Plugins" on the wiki for more info (we're currently at step 2 of the process)

ditman avatar Jul 10 '23 23:07 ditman

It looks like this is ready to split out the next PR, which is the web implementation. You'll just need to add in updating the version constraint for the interface package (and add a version bump).

stuartmorgan avatar Jul 20 '23 17:07 stuartmorgan

Update from triage: the blocking PR is in the queue to land now.

stuartmorgan avatar Sep 07 '23 18:09 stuartmorgan

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 or stuartmorgan on the #hackers channel in Chat (don't just cc them here, they won't see it! Use 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.

flutter-dashboard[bot] avatar Sep 09 '23 07:09 flutter-dashboard[bot]

Only the changes to the core package are remaining now, right?

ditman avatar Sep 13 '23 23:09 ditman

I just wrote up a whole comment on my confusion regarding this feature, and how I wasn't sure if the options were getting picked up and used by the controller... and then I:

  1. Realized that I was looking at only a subset of the PR.
  2. Found this parent PR.
  3. Saw that it hadn't merged yet.

Thanks for the work @defuncart , this will be super helpful!

wreppun avatar Oct 02 '23 20:10 wreppun

@defuncart Are you still planning on updating this to add tests, per the comment above?

stuartmorgan avatar Oct 10 '23 19:10 stuartmorgan

@stuartmorgan @ditman What type of tests are expected here? How can kIsWeb be mocked?

defuncart avatar Oct 11 '23 08:10 defuncart

What type of tests are expected here?

See my earlier comment. To put it another way: a test that would fail if the code you are adding in this PR were accidentally removed or broken by someone later.

How can kIsWeb be mocked?

You shouldn't need to mock it; we run Dart unit tests in both web and vm mode, so a test that is skipped on non-web will still run in CI.

stuartmorgan avatar Oct 11 '23 13:10 stuartmorgan

What type of tests are expected here?

See my earlier comment. To put it another way: a test that would fail if the code you are adding in this PR were accidentally removed or broken by someone later.

Thanks for the info, due to holidays, I won't be able to look into this for the next month. @wreppun if you'd like, feel free to take over adding the 🧪.

defuncart avatar Oct 17 '23 14:10 defuncart

I can only see 1 file change in this PR. Is this ready for review?

hellohuanlin avatar Oct 24 '23 04:10 hellohuanlin

Converting to a Draft; please feel free to mark this as ready for review once the tests have been added.

stuartmorgan avatar Dec 12 '23 20:12 stuartmorgan

any chance to merge this? This literally makes this lib unusable.

Thioby avatar Dec 18 '23 22:12 Thioby

@Thioby We cannot merge an uncompleted draft PR; anyone interested in accelerating the process of getting to a landable PR is welcome to contribute tests as discussed above.

stuartmorgan avatar Jan 02 '24 17:01 stuartmorgan

(triage): @defuncart Do you still have plans to come back to this PR and address the feedback given above?

goderbauer avatar Mar 05 '24 23:03 goderbauer

(triage): I am going to close this one since there hasn't been any follow-up. If you find the time to address the feedback given above please reopen this. Thank you.

goderbauer avatar May 07 '24 22:05 goderbauer

Assigning to myself to land this. Needs tests.

ditman avatar Jun 17 '24 20:06 ditman