Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f97c933
add option to not observe lifecycle
IlyaMax Sep 8, 2021
1c55067
remove redundant
IlyaMax Sep 8, 2021
2e025ae
merge
IlyaMax Sep 8, 2021
d29c804
Merge branch 'master' into add-option-to-not-observe-lifecycle-final-pr
IlyaMax Sep 8, 2021
db146f2
remove redundant version bump
IlyaMax Sep 9, 2021
0f89d4f
fix pubspec
IlyaMax Sep 9, 2021
4f0c4a1
remove redundant version bump again
IlyaMax Sep 9, 2021
e18a461
bump version of video player
IlyaMax Sep 9, 2021
c24e410
remove dependency
IlyaMax Sep 9, 2021
001065e
check ci
IlyaMax Sep 9, 2021
c2b2d23
rename option to allowBackgroundPlayback & add more tests on this
IlyaMax Dec 25, 2021
257d74d
Merge branch 'master' into add-option-to-not-observe-lifecycle-final-pr
IlyaMax Dec 25, 2021
765028b
Merge branch 'main' into add-option-to-not-observe-lifecycle-final-pr
IlyaMax Jan 7, 2022
6c1cb64
format
IlyaMax Jan 7, 2022
c5a1ef3
change video_player_platform_interface version in pubspec.yaml
IlyaMax Jan 7, 2022
98e2a18
bump video_player_web version
IlyaMax Jan 7, 2022
1d004c5
update versions to match semver
IlyaMax Jan 7, 2022
69a6cd5
update versions to match semver
IlyaMax Jan 7, 2022
996ddae
remove bump in video_player_web
IlyaMax Jan 21, 2022
f9eaf37
remove dependency override also
IlyaMax Jan 21, 2022
55cf52d
fix other nits
IlyaMax Jan 21, 2022
4081c00
Merge branch 'main' into add-option-to-not-observe-lifecycle-final-pr
IlyaMax Feb 11, 2022
6ffdfe0
Merge branch 'main' into add-option-to-not-observe-lifecycle-final-pr
IlyaMax Feb 11, 2022
96c2632
Merge branch 'main' into add-option-to-not-observe-lifecycle-final-pr
IlyaMax Feb 23, 2022
7e7c611
remove redundant changelog changes
IlyaMax Feb 23, 2022
c947b12
improve naming
IlyaMax Feb 23, 2022
3d5c12c
remove dependency overrides
IlyaMax Feb 23, 2022
1df2543
format
IlyaMax Feb 23, 2022
8a10969
Merge changes from pull request 4908 into current head
trevorknight Mar 7, 2022
3d26872
Fix analyzer error and video_player pubspec
trevorknight Mar 7, 2022
7c1f5a1
Fix lint checks
trevorknight Mar 7, 2022
76e8966
Fix bracket error in video player test
trevorknight Mar 7, 2022
25b4d47
Specify bool and final explicitly in video_player_test
trevorknight Mar 7, 2022
3ead931
Address comments: Fix pubspec and clarify test
trevorknight Mar 8, 2022
bd33594
Fix test method name
trevorknight Mar 8, 2022
ff69ad2
Remove trailing space
trevorknight Mar 8, 2022
2447544
Remove quotes from pubspec
stuartmorgan-g Mar 8, 2022
5aecc0a
Split true/false test into two tests
trevorknight Mar 8, 2022
7047179
Merge branch 'flutter:main' into mybackgroundplay
Mar 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/video_player/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.0

* Adds `allowBackgroundPlayback` to `VideoPlayerOptions`.

## 2.2.19

* Internal code cleanup for stricter analysis options.
Expand Down
12 changes: 8 additions & 4 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
bool _isDisposed = false;
Completer<void>? _creatingCompleter;
StreamSubscription<dynamic>? _eventSubscription;
late _VideoAppLifeCycleObserver _lifeCycleObserver;
_VideoAppLifeCycleObserver? _lifeCycleObserver;

/// The id of a texture that hasn't been initialized.
@visibleForTesting
Expand All @@ -309,8 +309,12 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {

/// Attempts to open the given [dataSource] and load metadata about the video.
Future<void> initialize() async {
_lifeCycleObserver = _VideoAppLifeCycleObserver(this);
_lifeCycleObserver.initialize();
final bool allowBackgroundPlayback =
videoPlayerOptions?.allowBackgroundPlayback ?? false;
if (!allowBackgroundPlayback) {
_lifeCycleObserver = _VideoAppLifeCycleObserver(this);
}
_lifeCycleObserver?.initialize();
_creatingCompleter = Completer<void>();

late DataSource dataSourceDescription;
Expand Down Expand Up @@ -423,7 +427,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
await _eventSubscription?.cancel();
await _videoPlayerPlatform.dispose(_textureId);
}
_lifeCycleObserver.dispose();
_lifeCycleObserver?.dispose();
}
_isDisposed = true;
super.dispose();
Expand Down
4 changes: 2 additions & 2 deletions packages/video_player/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter
widgets on Android, iOS, and web.
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.2.19
version: 2.3.0

environment:
sdk: ">=2.14.0 <3.0.0"
Expand All @@ -25,7 +25,7 @@ dependencies:
html: ^0.15.0
video_player_android: ^2.2.17
video_player_avfoundation: ^2.2.17
video_player_platform_interface: ">=4.2.0 <6.0.0"
video_player_platform_interface: ^5.1.0
video_player_web: ^2.0.0

dev_dependencies:
Expand Down
77 changes: 69 additions & 8 deletions packages/video_player/video_player/test/video_player_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ class _FakeClosedCaptionFile extends ClosedCaptionFile {
}

void main() {
void _verifyPlayStateRespondsToLifecycle(
VideoPlayerController controller, {
required bool shouldPlayInBackground,
}) {
expect(controller.value.isPlaying, true);
_ambiguate(WidgetsBinding.instance)!
.handleAppLifecycleStateChanged(AppLifecycleState.paused);
expect(controller.value.isPlaying, shouldPlayInBackground);
_ambiguate(WidgetsBinding.instance)!
.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
expect(controller.value.isPlaying, true);
}

testWidgets('update texture', (WidgetTester tester) async {
final FakeController controller = FakeController();
await tester.pumpWidget(VideoPlayer(controller));
Expand Down Expand Up @@ -194,6 +207,16 @@ 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();
_verifyPlayStateRespondsToLifecycle(controller,
shouldPlayInBackground: false);
});

test('asset', () async {
final VideoPlayerController controller = VideoPlayerController.asset(
'a.avi',
Expand Down Expand Up @@ -900,6 +923,46 @@ 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);
});

test('true allowBackgroundPlayback continues playback', () async {
final VideoPlayerController controller = VideoPlayerController.file(
File(''),
videoPlayerOptions: VideoPlayerOptions(
allowBackgroundPlayback: true,
),
);
await controller.initialize();
await controller.play();
_verifyPlayStateRespondsToLifecycle(
controller,
shouldPlayInBackground: true,
);
});

test('false allowBackgroundPlayback pauses playback', () async {
final VideoPlayerController controller = VideoPlayerController.file(
File(''),
videoPlayerOptions: VideoPlayerOptions(
allowBackgroundPlayback: false,
),
);
await controller.initialize();
await controller.play();
_verifyPlayStateRespondsToLifecycle(
controller,
shouldPlayInBackground: false,
);
});
});

test('VideoProgressColors', () {
const Color playedColor = Color.fromRGBO(0, 0, 255, 0.75);
const Color bufferedColor = Color.fromRGBO(0, 255, 0, 0.5);
Expand All @@ -914,14 +977,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 {
Expand Down Expand Up @@ -1010,3 +1065,9 @@ class FakeVideoPlayerPlatform extends VideoPlayerPlatform {
calls.add('setMixWithOthers');
}
}

/// This allows a value of type T or T? to be treated as a value of type T?.
///
/// We use this so that APIs that have become non-nullable can still be used
/// with `!` and `?` on the stable branch.
T? _ambiguate<T>(T? value) => value;