File tree Expand file tree Collapse file tree 9 files changed +187
-151
lines changed Expand file tree Collapse file tree 9 files changed +187
-151
lines changed Original file line number Diff line number Diff line change @@ -385,9 +385,9 @@ class MediaPlayerState extends State<MediaPlayer>
385
385
var _defaultBrightness = 0.0 ;
386
386
387
387
Future <void > _handleVolumeAndBrightness () async {
388
- VolumeController () .showSystemUI = false ;
389
- _volumeValue.value = await VolumeController () .getVolume ();
390
- VolumeController (). listener ((value) {
388
+ VolumeController .instance .showSystemUI = false ;
389
+ _volumeValue.value = await VolumeController .instance .getVolume ();
390
+ VolumeController .instance. addListener ((value) {
391
391
if (mounted && ! _volumeInterceptEventStream) {
392
392
_volumeValue.value = value;
393
393
}
@@ -409,7 +409,7 @@ class MediaPlayerState extends State<MediaPlayer>
409
409
Future <void > setVolume (double value) async {
410
410
if (! isMobile) return ;
411
411
try {
412
- VolumeController () .setVolume (value);
412
+ VolumeController .instance .setVolume (value);
413
413
} catch (_) {}
414
414
_volumeValue.value = value;
415
415
_volumeIndicator.value = true ;
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ import 'Theme/Colors.dart';
43
43
import 'Theme/ThemeManager.dart' ;
44
44
import 'Theme/ThemeProvider.dart' ;
45
45
import 'logger.dart' ;
46
+ import 'package:volume_controller/volume_controller.dart' ;
46
47
47
48
late Isar isar;
48
49
WebViewEnvironment ? webViewEnvironment;
@@ -240,13 +241,37 @@ late FloatingBottomNavBar navbar;
240
241
241
242
class MainActivityState extends State <MainActivity > {
242
243
int _selectedIndex = 1 ;
244
+ late final VolumeController _volumeController;
245
+ late final StreamSubscription <double > _subscription;
246
+ double _currentVolume = 0 ;
247
+ double _volumeValue = 0 ;
248
+ bool _isMuted = false ;
243
249
244
250
void _onTabSelected (int index) => setState (() => _selectedIndex = index);
245
251
246
252
@override
247
253
void initState () {
248
254
super .initState ();
249
255
checkForUpdate ();
256
+ _volumeController = VolumeController .instance;
257
+
258
+
259
+ // Listen to system volume change
260
+ _subscription = _volumeController.addListener ((volume) {
261
+ setState (() => _volumeValue = volume);
262
+ }, fetchInitialVolume: true );
263
+
264
+ _volumeController
265
+ .isMuted ()
266
+ .then ((isMuted) => setState (() => _isMuted = isMuted));
267
+
268
+ }
269
+ @override
270
+ void dispose (){
271
+ _subscription.cancel ();
272
+ super .dispose ();
273
+
274
+
250
275
}
251
276
252
277
@override
Original file line number Diff line number Diff line change 15
15
#include < media_kit_video/media_kit_video_plugin.h>
16
16
#include < screen_retriever_linux/screen_retriever_linux_plugin.h>
17
17
#include < url_launcher_linux/url_launcher_plugin.h>
18
+ #include < volume_controller/volume_controller_plugin.h>
18
19
#include < window_manager/window_manager_plugin.h>
19
20
#include < window_to_front/window_to_front_plugin.h>
20
21
@@ -46,6 +47,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
46
47
g_autoptr (FlPluginRegistrar) url_launcher_linux_registrar =
47
48
fl_plugin_registry_get_registrar_for_plugin (registry, " UrlLauncherPlugin" );
48
49
url_launcher_plugin_register_with_registrar (url_launcher_linux_registrar);
50
+ g_autoptr (FlPluginRegistrar) volume_controller_registrar =
51
+ fl_plugin_registry_get_registrar_for_plugin (registry, " VolumeControllerPlugin" );
52
+ volume_controller_plugin_register_with_registrar (volume_controller_registrar);
49
53
g_autoptr (FlPluginRegistrar) window_manager_registrar =
50
54
fl_plugin_registry_get_registrar_for_plugin (registry, " WindowManagerPlugin" );
51
55
window_manager_plugin_register_with_registrar (window_manager_registrar);
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
12
12
media_kit_video
13
13
screen_retriever_linux
14
14
url_launcher_linux
15
+ volume_controller
15
16
window_manager
16
17
window_to_front
17
18
)
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import share_plus
24
24
import shared_preferences_foundation
25
25
import sqflite_darwin
26
26
import url_launcher_macos
27
+ import volume_controller
27
28
import wakelock_plus
28
29
import webview_flutter_wkwebview
29
30
import window_manager
@@ -49,8 +50,9 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
49
50
SharedPreferencesPlugin . register ( with: registry. registrar ( forPlugin: " SharedPreferencesPlugin " ) )
50
51
SqflitePlugin . register ( with: registry. registrar ( forPlugin: " SqflitePlugin " ) )
51
52
UrlLauncherPlugin . register ( with: registry. registrar ( forPlugin: " UrlLauncherPlugin " ) )
53
+ VolumeControllerPlugin . register ( with: registry. registrar ( forPlugin: " VolumeControllerPlugin " ) )
52
54
WakelockPlusMacosPlugin . register ( with: registry. registrar ( forPlugin: " WakelockPlusMacosPlugin " ) )
53
- FLTWebViewFlutterPlugin . register ( with: registry. registrar ( forPlugin: " FLTWebViewFlutterPlugin " ) )
55
+ WebViewFlutterPlugin . register ( with: registry. registrar ( forPlugin: " WebViewFlutterPlugin " ) )
54
56
WindowManagerPlugin . register ( with: registry. registrar ( forPlugin: " WindowManagerPlugin " ) )
55
57
WindowToFrontPlugin . register ( with: registry. registrar ( forPlugin: " WindowToFrontPlugin " ) )
56
58
}
You can’t perform that action at this time.
0 commit comments