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

Conversation

@IlyaMax
Copy link
Contributor

@IlyaMax IlyaMax commented Sep 8, 2021

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

  • 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]. (Note that 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].
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • All existing and new tests are passing.

@google-cla
Copy link

google-cla bot commented Sep 8, 2021

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 @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@IlyaMax
Copy link
Contributor Author

IlyaMax commented Sep 8, 2021

@googlebot I signed it!

@google-cla google-cla bot added cla: yes and removed cla: no labels Sep 8, 2021
@IlyaMax IlyaMax changed the title Added new field observeAppLifecycle to enable background playing of video [video_player] Added new field observeAppLifecycle to enable background playing of video Sep 8, 2021
@stuartmorgan-g
Copy link
Contributor

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.

@ZhangZhiH
Copy link

@IlyaMax
hello
All I see is an observeAppLifecycle
But I don't see background playback implemented there
How to play video in background

@IlyaMax
Copy link
Contributor Author

IlyaMax commented Oct 4, 2021

@ZhangZhiH audio playback is active when you close application or lock screen. if you mean picture in picture, it is not related.

@ZhangZhiH
Copy link

@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
But I can't implement this feature right now
I currently have video_Player version 1.0.1
Is there anything I can do
I have looked at the changes you submitted and found that this feature is also not implemented

@ZhangZhiH
Copy link

@ZhangZhiH audio playback is active when you close application or lock screen. if you mean picture in picture, it is not related.

This problem now finds a solution
Use audio player when switching lock screen
Change back to the video player when cutting back to the page and synchronize the progress

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.

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;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe needBackgroundPlayback?

Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@ZhangZhiH

This comment has been minimized.

@blessedman
Copy link

It looks like background playback will be supported soon

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.

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`
Copy link
Contributor

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,
Copy link
Contributor

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 {
Copy link
Contributor

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', () {
Copy link
Contributor

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`
Copy link
Contributor

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,
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

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-g stuartmorgan-g requested review from gaaclarke and removed request for LHLL, bparrishMines, cyanglaz and ditman January 21, 2022 18:13
@flutter flutter deleted a comment from ZhangZhiH Jan 21, 2022
@IlyaMax
Copy link
Contributor Author

IlyaMax commented Jan 27, 2022

@stuartmorgan What do you think about removing allowBackgroundPlayback option from VideoPlayerOptions to simplify this pr? As possible solution I think we can rename VideoPlayerOptions to something like NativeVideoPlayerOptions and make it private for plugin, because allowBackgroundPlayback setting configure dart behavior and create VideoPlayerOptions which duplicates NativeVideoPlayerOptions fields . For example I have idea also to provide option not to recover playing state after AppLifecycleState.resumed which is handled also only on dart side.

@stuartmorgan-g
Copy link
Contributor

As possible solution I think we can rename VideoPlayerOptions to something like NativeVideoPlayerOptions

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 hide and import as to avoid collisions, but I think that's probably more confusing than just dealing with needing to make Dart-only additions in the platform interface.

@IlyaMax
Copy link
Contributor Author

IlyaMax commented Jan 27, 2022

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.

@stuartmorgan-g
Copy link
Contributor

(We could theoretically a new secondary options class—e.g., VideoPlayerControllerOptions—and make it an additional optional argument, but that would make the public-facing API really confusing, so isn't something I'd actually want to do.)

@stuartmorgan-g
Copy link
Contributor

@gaaclarke Ping on secondary review

Copy link
Member

@gaaclarke gaaclarke left a 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 =
Copy link
Member

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?

Copy link
Contributor

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(
Copy link
Member

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?

@stuartmorgan-g
Copy link
Contributor

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

@IlyaMax
Copy link
Contributor Author

IlyaMax commented Feb 17, 2022

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

@gaaclarke
Copy link
Member

@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 surfstudio:add-option-to-not-observe-lifecycle-final-pr.

Some thing like:

git clone [email protected]:flutter/plugins.git
cd plugins
git checkout origin/add-option-to-not-observe-lifecycle-final-pr -b add-option-to-not-observe-lifecycle-final-pr

Alternatively you could try using github's built in editor so you can edit the files without downloading them locally.

@IlyaMax
Copy link
Contributor Author

IlyaMax commented Feb 19, 2022

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

image

I can't checkout pr branches. Is this so critical if I create a new pr and link this pr there?

@stuartmorgan-g
Copy link
Contributor

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

@IlyaMax
Copy link
Contributor Author

IlyaMax commented Feb 22, 2022

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants