Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
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 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
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.18

* Moves Android and iOS implementations to federated packages.
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 @@ -294,7 +294,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 @@ -308,8 +308,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 allowBackgroundPlayback =
videoPlayerOptions?.allowBackgroundPlayback ?? false;
if (!allowBackgroundPlayback) {
_lifeCycleObserver = _VideoAppLifeCycleObserver(this);
}
_lifeCycleObserver?.initialize();
_creatingCompleter = Completer<void>();

late DataSource dataSourceDescription;
Expand Down Expand Up @@ -424,7 +428,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
await _eventSubscription?.cancel();
await _videoPlayerPlatform.dispose(_textureId);
}
_lifeCycleObserver.dispose();
_lifeCycleObserver?.dispose();
}
_isDisposed = true;
super.dispose();
Expand Down
2 changes: 1 addition & 1 deletion 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.18
version: 2.3.0

Copy link
Contributor

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.

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
60 changes: 52 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,22 @@ class _FakeClosedCaptionFile extends ClosedCaptionFile {
}

void main() {
void verifyPlayingWhenAppLifecyclePaused(
VideoPlayerController controller, {
required bool isObserving,
}) {
final wasPlayingBeforePause = controller.value.isPlaying;
WidgetsBinding.instance!
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll need to add _ambiguate to this file and call it on these lines to fix the analyzer issue on master.

.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));
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down