-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[video_player] Added new field allowBackgroundPlayback to enable background playing of video #4324
[video_player] Added new field allowBackgroundPlayback to enable background playing of video #4324
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
|
@googlebot I signed it! |
|
Thanks for the submission! We’re currently working through a large backlog of PRs, and this will require non-trivial review, so it will take some time before we’re able to review it. As explained in CONTRIBUTING.md, votes for the corresponding issue are the primary way we’re prioritizing non-trivial reviews, so we encourage anyone interested in this PR to vote for the corresponding issue. |
|
@IlyaMax |
|
@ZhangZhiH audio playback is active when you close application or lock screen. if you mean picture in picture, it is not related. |
Yeah, I want the video to keep playing after I lock the screen |
This problem now finds a solution |
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.
Overall this change seems reasonable, it'll just need more meaningful testing.
| /// Set this to true to let plugin manage play/pause with app lifecycle changes, | ||
| /// Set this to false to keep playing video in background, when app goes in background | ||
| /// The default value is true | ||
| final bool observeAppLifecycle; |
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 think it would make more sense to call this pauseInBackground or similar; observing the app lifecycle is how it's implemented, not the actual user intent of the option.
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.
maybe needBackgroundPlayback?
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'm not sure about "need", but allowBackgroundPlayback sounds good to me.
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.
fixed
| File(''), | ||
| videoPlayerOptions: VideoPlayerOptions(observeAppLifecycle: true)); | ||
| await controller.initialize(); | ||
| expect(controller.videoPlayerOptions!.observeAppLifecycle, true); |
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.
This is testing that the options struct isn't modified when it's passed it, but that's all; if your changes to initialize() that honor this option were reverted the test would still pass. This needs a real test that the option is being honored.
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.
You mean I need to validate _VideoAppLifeCycleObserver doesn't work if flag is specified?
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.
The purpose of a test is to verify that a change works. If I can remove the key part of a change and the test would still pass (which is true here), then the test isn't actually testing the feature.
I haven't tried this, but I believe you could call WidgetsBinding.instance!.handleAppLifecycleStateChanged(AppLifecycleState.paused) in the test and assert that it doesn't pause. You should similarly add a test that does that with the option set the other way and ensure that it does.
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.
fixed
This comment has been minimized.
This comment has been minimized.
|
It looks like background playback will be supported soon |
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.
Some nits, but this looks good overall.
@gaaclarke for secondary review before we split out the platform interface change.
| @@ -1,3 +1,7 @@ | |||
| ## 2.3.0 | |||
|
|
|||
| * Add `allowBackgroundPlayback` to `VideoPlayerOptions` | |||
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.
Nit: Adds
(Per new repo CHANGELOG style guide)
| void main() { | ||
| void verifyAppLifeCycle( | ||
| VideoPlayerController controller, { | ||
| bool isObserving = true, |
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 make this required instead of having a default value; it's better for tests to be as explicit as possible.
| await controller.play(); | ||
| verifyAppLifeCycle(controller); | ||
| }); | ||
| test('asset', () async { |
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.
Nit: blank line between tests please.
| expect(controller.videoPlayerOptions!.mixWithOthers, true); | ||
| }); | ||
|
|
||
| group('allowBackgroundPlayback', () { |
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.
Excessive nesting of groups makes IDE UIs harder to use; this can be removed, and the test name below updated to include this string in the name.
| @@ -1,3 +1,7 @@ | |||
| ## 5.1.0 | |||
|
|
|||
| * Add `allowBackgroundPlayback` to `VideoPlayerOptions` | |||
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.
Nit: Adds
Nit: Missing period at end of sentence
|
|
||
| /// [VideoPlayerOptions] can be optionally used to set additional player settings | ||
| class VideoPlayerOptions { | ||
| /// Set this to false to let plugin manage play/pause with app lifecycle changes, |
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.
Remove this sentence; you don't generally need to document both options for a bool since they are inverse of each other.
| /// [VideoPlayerOptions] can be optionally used to set additional player settings | ||
| class VideoPlayerOptions { | ||
| /// Set this to false to let plugin manage play/pause with app lifecycle changes, | ||
| /// Set this to true to keep playing video in background, when app goes in background |
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.
Nit: missing period.
| @@ -1,3 +1,7 @@ | |||
| ## 2.0.6 | |||
|
|
|||
| * Bump `video_player_platform_interface` version | |||
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.
Why?
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.
wasn't sure about this change. I had problems with building example without this. But maybe that because there weren't versions constraints when I published pr.
|
@stuartmorgan What do you think about removing |
That would be a good option, except that it would be a breaking change for the platform interface package, which we only do when necessary. We could potentially use the same name and some combination of |
|
Yes, it seems that breaking change is not reasonable for now. There are no options to configure on dart apart from these two, at least I can't think of them. |
|
(We could theoretically a new secondary options class—e.g., |
|
@gaaclarke Ping on secondary review |
gaaclarke
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
| Future<void> initialize() async { | ||
| _lifeCycleObserver = _VideoAppLifeCycleObserver(this); | ||
| _lifeCycleObserver.initialize(); | ||
| final allowBackgroundPlayback = |
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.
nit: The linter isn't flagging this for omitting the datatype?
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.
We haven't converted video_player off of the legacy options yet unfortunately.
| } | ||
|
|
||
| void main() { | ||
| void verifyAppLifeCycle( |
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.
nit: this name isn't very helpful. Something like verifyPlayingWhenAppLifeCyclePaused?
|
@IlyaMax Since we're down to just very minor nits now, please feel free to open the platform interface PR, and we can start getting the pieces of this landed :) |
|
@stuartmorgan is it ok if I close this pr and open a new one? I've deleted old repo, so I'm not sure how I can fix nits without opening new pr. |
The code still exists on github and you can check it out at Some thing like: Alternatively you could try using github's built in editor so you can edit the files without downloading them locally. |
|
@gaaclarke this doesn't work unfortunately. This branch has conflicts so it will be hard to manage with this in web editor. In both my new fork and clone this is the list of available branches. I can't checkout pr branches. Is this so critical if I create a new pr and link this pr there? |
|
Given that you've deleted the remote repository, I don't think there's anything you can do other than make a new PR. AFAIK GitHub doesn't allow changing the source of a PR after the fact. (In the future, please don't delete the repository hosting an active PR. Changing PRs is disruptive to the review process since we can't see incremental diffs and can't easily reference previous comments.) |
|
@stuartmorgan Actually I thought that this can be handled with git/github, so didn't think of that. Deleting repos is not something which I do often) but will take this into account next time, yes. |

Description
This PR introduces a new option to VideoPlayerOptions, which enables user to decide on whether user wants to keep playing video in the background or not.
This is a much requested feature, in many issues.
Related issues
63836 - flutter/flutter#63836
63735 - flutter/flutter#63735
55673 - flutter/flutter#55673
48008 - flutter/flutter#48008
40722 - flutter/flutter#40722
32571 - flutter/flutter#32571
Pre-launch Checklist
dart format.)[shared_preferences]///).