This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[video_player] Added new option allowBackgroundPlayback #4908
Closed
IlyaMax
wants to merge
28
commits into
flutter:main
from
surfstudio:add-option-to-not-observe-lifecycle-final-pr
Closed
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f97c933
add option to not observe lifecycle
IlyaMax 1c55067
remove redundant
IlyaMax 2e025ae
merge
IlyaMax d29c804
Merge branch 'master' into add-option-to-not-observe-lifecycle-final-pr
IlyaMax db146f2
remove redundant version bump
IlyaMax 0f89d4f
fix pubspec
IlyaMax 4f0c4a1
remove redundant version bump again
IlyaMax e18a461
bump version of video player
IlyaMax c24e410
remove dependency
IlyaMax 001065e
check ci
IlyaMax c2b2d23
rename option to allowBackgroundPlayback & add more tests on this
IlyaMax 257d74d
Merge branch 'master' into add-option-to-not-observe-lifecycle-final-pr
IlyaMax 765028b
Merge branch 'main' into add-option-to-not-observe-lifecycle-final-pr
IlyaMax 6c1cb64
format
IlyaMax c5a1ef3
change video_player_platform_interface version in pubspec.yaml
IlyaMax 98e2a18
bump video_player_web version
IlyaMax 1d004c5
update versions to match semver
IlyaMax 69a6cd5
update versions to match semver
IlyaMax 996ddae
remove bump in video_player_web
IlyaMax f9eaf37
remove dependency override also
IlyaMax 55cf52d
fix other nits
IlyaMax 4081c00
Merge branch 'main' into add-option-to-not-observe-lifecycle-final-pr
IlyaMax 6ffdfe0
Merge branch 'main' into add-option-to-not-observe-lifecycle-final-pr
IlyaMax 96c2632
Merge branch 'main' into add-option-to-not-observe-lifecycle-final-pr
IlyaMax 7e7c611
remove redundant changelog changes
IlyaMax c947b12
improve naming
IlyaMax 3d5c12c
remove dependency overrides
IlyaMax 1df2543
format
IlyaMax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,22 @@ class _FakeClosedCaptionFile extends ClosedCaptionFile { | |
| } | ||
|
|
||
| void main() { | ||
| void verifyPlayingWhenAppLifecyclePaused( | ||
| VideoPlayerController controller, { | ||
| required bool isObserving, | ||
| }) { | ||
| final wasPlayingBeforePause = controller.value.isPlaying; | ||
| WidgetsBinding.instance! | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll need to add |
||
| .handleAppLifecycleStateChanged(AppLifecycleState.paused); | ||
| expect( | ||
| controller.value.isPlaying, | ||
| isObserving ? false : wasPlayingBeforePause, | ||
| ); | ||
| WidgetsBinding.instance! | ||
| .handleAppLifecycleStateChanged(AppLifecycleState.resumed); | ||
| expect(controller.value.isPlaying, wasPlayingBeforePause); | ||
| } | ||
|
|
||
| testWidgets('update texture', (WidgetTester tester) async { | ||
| final FakeController controller = FakeController(); | ||
| await tester.pumpWidget(VideoPlayer(controller)); | ||
|
|
@@ -192,6 +208,15 @@ void main() { | |
| }); | ||
|
|
||
| group('initialize', () { | ||
| test('started app lifecycle observing', () async { | ||
| final VideoPlayerController controller = VideoPlayerController.network( | ||
| 'https://127.0.0.1', | ||
| ); | ||
| await controller.initialize(); | ||
| await controller.play(); | ||
| verifyPlayingWhenAppLifecyclePaused(controller, isObserving: true); | ||
| }); | ||
|
|
||
| test('asset', () async { | ||
| final VideoPlayerController controller = VideoPlayerController.asset( | ||
| 'a.avi', | ||
|
|
@@ -899,6 +924,33 @@ void main() { | |
| }); | ||
| }); | ||
|
|
||
| group('VideoPlayerOptions', () { | ||
| test('setMixWithOthers', () async { | ||
| final VideoPlayerController controller = VideoPlayerController.file( | ||
| File(''), | ||
| videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true)); | ||
| await controller.initialize(); | ||
| expect(controller.videoPlayerOptions!.mixWithOthers, true); | ||
| }); | ||
|
|
||
| [true, false].forEach((allowBackgroundPlayback) { | ||
| test('allowBackgroundPlayback is $allowBackgroundPlayback', () async { | ||
| final VideoPlayerController controller = VideoPlayerController.file( | ||
| File(''), | ||
| videoPlayerOptions: VideoPlayerOptions( | ||
| allowBackgroundPlayback: allowBackgroundPlayback, | ||
| ), | ||
| ); | ||
| await controller.initialize(); | ||
| await controller.play(); | ||
| verifyPlayingWhenAppLifecyclePaused( | ||
| controller, | ||
| isObserving: !allowBackgroundPlayback, | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| test('VideoProgressColors', () { | ||
| const Color playedColor = Color.fromRGBO(0, 0, 255, 0.75); | ||
| const Color bufferedColor = Color.fromRGBO(0, 255, 0, 0.5); | ||
|
|
@@ -913,14 +965,6 @@ void main() { | |
| expect(colors.bufferedColor, bufferedColor); | ||
| expect(colors.backgroundColor, backgroundColor); | ||
| }); | ||
|
|
||
| test('setMixWithOthers', () async { | ||
| final VideoPlayerController controller = VideoPlayerController.file( | ||
| File(''), | ||
| videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true)); | ||
| await controller.initialize(); | ||
| expect(controller.videoPlayerOptions!.mixWithOthers, true); | ||
| }); | ||
| } | ||
|
|
||
| class FakeVideoPlayerPlatform extends VideoPlayerPlatform { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 need to update the video_player_platform_interface minimum version to require the version that added the new option. As written someone's project could pass through package resolution with a version that wouldn't compile.