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

[video_player] Add setClosedCaptionFile method to VideoPlayerController#5105

Merged
fluttergithubbot merged 16 commits intoflutter:mainfrom
ibrahimcetin:set-closed-caption-file
Apr 21, 2022
Merged

[video_player] Add setClosedCaptionFile method to VideoPlayerController#5105
fluttergithubbot merged 16 commits intoflutter:mainfrom
ibrahimcetin:set-closed-caption-file

Conversation

@ibrahimcetin
Copy link
Copy Markdown
Contributor

@ibrahimcetin ibrahimcetin commented Mar 24, 2022

This PR adds setClosedCaptionFile method to VideoPlayerController to add, change or remove closedCaptionFile.

Fixes flutter/flutter#100302

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.

Copy link
Copy Markdown
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.

Thanks for the submission!

Copy link
Copy Markdown
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.

Looks good other than the version issue.

@bparrishMines Could you do the secondary review here?

@@ -1,6 +1,7 @@
## NEXT
## 2.3.1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, I missed this before: this version change should be 2.4.0 rather than 2.3.1, since this is a new feature rather than a bugfix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I updated

repository: https://github.com/flutter/plugins/tree/main/packages/video_player/video_player
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.3.0
version: 2.3.1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs to match.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

## 2.4.0

* Updates minimum Flutter version to 2.10.
* Adds `setClosedCaptionFile` method to `VideoPlayerController`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: missing period at the end (missed this in the previous review).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This hasn't been resolved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Still not resolved.

///
/// If [closedCaptionFile] is null, closed caption file will be removed.
Future<void> setClosedCaptionFile(
Future<ClosedCaptionFile>? closedCaptionFile,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this would be better as FutureOr<ClosedCaptionFile?> closedCaptionFile so a user wouldn't have to use Future.value() to pass a value synchronously.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or better yet, I think just making it synchronous would be best if possible: ClosedCaptionFile? closedCaptionFile.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, I made it synchronous but then I turned it to async because closedCaptionFile parameter in initialize method is async. I don't know why closedCaptionFile parameter is Future but I thought if they made it Future, there was a logic behind it. However, my main thought is to make it synchronous as I mentioned in the issue (In short, removing closedCaptionFile parameter and adding a sync setter and getter for closedCaptionFile). But this would be a breaking change, so I decided to add just a setter method. I discussed this with stuartmorgan but I want to ask that question to you too because I'm wondering your thoughts, Can we make this breaking change? I think synchronous would be better in general.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I missed in my review that you didn't change final Future<ClosedCaptionFile>? closedCaptionFile; to a getter, which was part of what we discussed. This change will leave the public accessor returning the wrong file.

(That should also be added to the tests, since it was missed.)

Can we make this breaking change

We are not making a breaking change in video_player for this; that's a disruptive change, and this is a niche use case that can easily be accommodated by a non-breaking change.

@bparrishMines I forgot the previous discussion was in Discord rather than here, so you wouldn't have context, sorry about that. I suggested the Future<> version for consistency; I could see an argument for making it take a file directly and then convert to a Future internally for compatibility with the existing public getter API; I don't have a strong opinion on that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I hadn't realized this was already discussed. No worries. This solution sounds good to me! (Assuming @stuartmorgan will wait for the accessor change.)

Copy link
Copy Markdown
Contributor Author

@ibrahimcetin ibrahimcetin Apr 13, 2022

Choose a reason for hiding this comment

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

A getter does not allow assigning a value (nor is the final keyword applicable to it)

Yes, I know.

To be honest, I don't know how to change final Future<ClosedCaptionFile>? closedCaptionFile; to a getter. I turned it to Future<ClosedCaptionFile>? closedCaptionFile; but it became assignable. That's what i'm trying to say. So, how can I change it to a getter?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe @stuartmorgan was thinking something like:

VideoPlayerController.asset(/*other params*/, {Future<closedCaptionFile>? closedCaptionFile, /*otherparams*/})
      : _closedCaptionFile = closedCaptionFile;

Future<ClosedCaptionFile>? _closedCaptionFile;

Future<ClosedCaptionFile>? get closedCaptionFile {
  return _closedCaptureFile;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Exactly, with the caveat that the member variable will need to be called something like _closedCaptionFileFuture since there's already a _closedCaptionFile.

To be honest, I don't know how to change final Future<ClosedCaptionFile>? closedCaptionFile; to a getter. I turned it to Future<ClosedCaptionFile>? closedCaptionFile; but it became assignable. That's what i'm trying to say.

In the future, if you aren't sure how to implement a suggestion it is much more effective to simply ask, rather than doing something completely different without explaining what you did and then ask questions about that instead. I had absolutely no context for the question you were asking since I didn't know what the code you'd actually written was (or that it was different from my suggestion).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Exactly, with the caveat that the member variable will need to be called something like _closedCaptionFileFuture since there's already a _closedCaptionFile.

Thanks for the answer. I implemented this and everything works fine except the document. Now, the closedCaptionFile parameter shows the constructors' document. (I'm not talking about the getter, its document is ok)

In the future, if you aren't sure how to implement a suggestion it is much more effective to simply ask, rather than doing something completely different without explaining what you did and then ask questions about that instead. I had absolutely no context for the question you were asking since I didn't know what the code you'd actually written was (or that it was different from my suggestion).

Thanks for your feedback. I'll do.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I committed the changes

///
/// If [closedCaptionFile] is null, closed caption file will be removed.
Future<void> setClosedCaptionFile(
Future<ClosedCaptionFile>? closedCaptionFile,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I missed in my review that you didn't change final Future<ClosedCaptionFile>? closedCaptionFile; to a getter, which was part of what we discussed. This change will leave the public accessor returning the wrong file.

(That should also be added to the tests, since it was missed.)

Can we make this breaking change

We are not making a breaking change in video_player for this; that's a disruptive change, and this is a niche use case that can easily be accommodated by a non-breaking change.

@bparrishMines I forgot the previous discussion was in Discord rather than here, so you wouldn't have context, sorry about that. I suggested the Future<> version for consistency; I could see an argument for making it take a file directly and then convert to a Future internally for compatibility with the existing public getter API; I don't have a strong opinion on that.

Copy link
Copy Markdown
Contributor

@bparrishMines bparrishMines left a comment

Choose a reason for hiding this comment

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

LGTM

## 2.4.0

* Updates minimum Flutter version to 2.10.
* Adds `setClosedCaptionFile` method to `VideoPlayerController`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This hasn't been resolved.

/// This future will be awaited and the file will be loaded when
/// [initialize()] is called.
final Future<ClosedCaptionFile>? closedCaptionFile;
Future<ClosedCaptionFile>? get closedCaptionFile {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please put this after the field declarations, not in the middle of them. Right before setClosedCaptionFile would be the best place.

_closedCaptionFile ??= await closedCaptionFile;
value = value.copyWith(caption: _getCaptionAt(value.position));
if (_closedCaptionFileFuture != null) {
await setClosedCaptionFile(_closedCaptionFileFuture);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Calling the setter to set the same value that the field is already set to in order to benefit from side-effects in the setter is an anti-pattern; it makes the code less understandable, and is subject to subtle breakage if someone later optimizes the setter to be a no-op if the new and old values are the same.

The way to share code here would be to make a new _updateClosedCaptionWithFuture(...) method and put the logic there, then implement both initialize and setClosedCaptionFile using that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I guess everything is okay now.

## 2.4.0

* Updates minimum Flutter version to 2.10.
* Adds `setClosedCaptionFile` method to `VideoPlayerController`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Still not resolved.

return Caption.none;
}

/// Optional field to specify a file containing the closed
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This sentence is no longer correct, since it's not a field now.

/// Returns the file containing closed captions for the video, if any.


/// Sets a closed caption file.
///
/// If [closedCaptionFile] is null, closed caption file will be removed.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

s/closed caption file/closed captions/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't understand what you mean

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, I shouldn't use that shorthand in reviews.

Please replace "closed caption file" with "closed captions" in this comment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just the second.

@ibrahimcetin
Copy link
Copy Markdown
Contributor Author

Hope everything is fine now. And by the way, I want to thank you for your help @stuartmorgan.

@stuartmorgan-g
Copy link
Copy Markdown
Contributor

The CHANGELOG issue that I've commented on three times is still unaddressed. We do require that PRs follow our style guides (which is why it's part of the checklist).

@ibrahimcetin
Copy link
Copy Markdown
Contributor Author

Sorry, my bad

Copy link
Copy Markdown
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, thanks!

@stuartmorgan-g stuartmorgan-g added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Apr 21, 2022
@fluttergithubbot fluttergithubbot merged commit f2dd3d9 into flutter:main Apr 21, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 22, 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

p: video_player waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[video_player] Proposal to update the Video Player Caption post initialization

4 participants