From cd647f8557536547f8f76bab867116f860dfa1c2 Mon Sep 17 00:00:00 2001 From: tbansod2018 Date: Wed, 9 Oct 2024 12:21:41 +0530 Subject: [PATCH 1/2] not seting volume when muted --- .../video_player_web/lib/src/video_player.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/video_player/video_player_web/lib/src/video_player.dart b/packages/video_player/video_player_web/lib/src/video_player.dart index 72f4b7dc155b..958540169cc0 100644 --- a/packages/video_player/video_player_web/lib/src/video_player.dart +++ b/packages/video_player/video_player_web/lib/src/video_player.dart @@ -179,8 +179,12 @@ 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 (volume > 0.0) { + _videoElement.muted = false; + _videoElement.volume = volume; + } else { + _videoElement.muted = true; + } } /// Sets the playback `speed`. From e6b9ca027d87a792ae6eeea50384fea68c2de710 Mon Sep 17 00:00:00 2001 From: tbansod2018 Date: Sat, 12 Oct 2024 00:39:00 +0530 Subject: [PATCH 2/2] test added for seting volume --- .../integration_test/video_player_test.dart | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/video_player/video_player_web/example/integration_test/video_player_test.dart b/packages/video_player/video_player_web/example/integration_test/video_player_test.dart index 51199ba79d2b..7b6f1679c83c 100644 --- a/packages/video_player/video_player_web/example/integration_test/video_player_test.dart +++ b/packages/video_player/video_player_web/example/integration_test/video_player_test.dart @@ -57,6 +57,31 @@ void main() { }, throwsAssertionError, reason: 'Volume cannot be > 1'); }); + testWidgets('setVolume correctly handles mute and volume states', + (WidgetTester tester) async { + final VideoPlayer player = VideoPlayer(videoElement: video)..initialize(); + + // Test setting volume > 0 (should unmute and set the volume) + player.setVolume(0.5); + expect(video.volume, equals(0.5), reason: 'Volume should be 0.5'); + expect(video.muted, isFalse, reason: 'muted attribute should be false'); + + // Test setting volume to 0 (should mute the video) + player.setVolume(0.0); + expect(video.volume, equals(0.0), reason: 'Volume should be zero'); + expect(video.muted, isTrue, reason: 'muted attribute should be true'); + + // Ensure setting negative volume still throws an assertion + expect(() { + player.setVolume(-0.1); + }, throwsAssertionError, reason: 'Volume cannot be < 0'); + + // Ensure setting volume greater than 1 throws an assertion + expect(() { + player.setVolume(1.1); + }, throwsAssertionError, reason: 'Volume cannot be > 1'); + }); + testWidgets('setPlaybackSpeed', (WidgetTester tester) async { final VideoPlayer player = VideoPlayer(videoElement: video)..initialize();