Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[video_player_web] Don't modify volume when muting video #7845

Merged
merged 14 commits into from
Oct 25, 2024
3 changes: 2 additions & 1 deletion packages/video_player/video_player_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 2.3.3

* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
* Corrects the behavior of muting/unmuting videos in Chrome's Tap Emulation mode.

## 2.3.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ void main() {
final VideoPlayer player = VideoPlayer(videoElement: video)..initialize();

player.setVolume(0);

expect(video.volume, isZero, reason: 'Volume should be zero');
expect(video.muted, isTrue, reason: 'muted attribute should be true');
// If the volume is set to zero, pressing unmute
// button may not restore the audio as expected.
expect(video.volume, greaterThan(0),
reason: 'Volume should not be set to zero when muted');
player.setVolume(0.5);
expect(video.volume, 0.5, reason: 'Volume should be set to 0.5');
expect(video.muted, isFalse, reason: 'Muted attribute should be false');

expect(() {
player.setVolume(-0.0001);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,13 @@ class VideoPlayer {

// TODO(ditman): Do we need to expose a "muted" API?
// https://github.com/flutter/flutter/issues/60721
_videoElement.muted = !(volume > 0.0);
_videoElement.volume = volume;

// If the volume is set to 0.0, only change muted attribute, but don't adjust the volume.
_videoElement.muted = volume == 0.0;
// Set the volume only if it's greater than 0.0.
if (volume > 0.0) {
_videoElement.volume = volume;
}
}

/// Sets the playback `speed`.
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player/video_player_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player_web
description: Web platform implementation of video_player.
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.3.2
version: 2.3.3

environment:
sdk: ^3.4.0
Expand Down