yosemiteyss / flutter_volume_controller

A Flutter plugin to control system volume and listen for volume changes on different platforms.
https://pub.dev/packages/flutter_volume_controller
MIT License
16 stars 9 forks source link

Calls result in PlatformExceptions #46

Open melio-matt opened 1 year ago

melio-matt commented 1 year ago

I'm running my Flutter app on a MacOS Ventura 13.3.1 and calling all of the APIs results in errors of the following code. I'm running my app off the command line 'flutter run -d macos'. I've read the readme files and not see there any permissions to set or initialisation procedure that I must do and I'm just copying the examples.

PlatformException(1004, Failed to register volume listener, The operation couldn’t be completed. (flutter_volume_controller.Sound.SoundOutputManager.Errors error 1.), null)

PlatformException(1000, Failed to get volume, The operation couldn’t be completed. (flutter_volume_controller.Sound.SoundOutputManager.Errors error 1.), null)

I've done a flutter clean and rebuild but that didn't change anything. A Google search did not yield any results, hence my post here as I don't currently see what else to try as the API is pretty straight forward.

yosemiteyss commented 1 year ago

Hi, can you provide more context? Like what sound output device you have selected?

melio-matt commented 1 year ago

Hi From your comment output device does seem to be critical here. When I was trying this I had my MacBook connected to my monitor via USB-C and the sound was being outputted by my monitor to some speakers. In this configuration I get the exception. When disconnecting my MacBook and using its internal speakers everything worked fine. I do have noted that when my machine is connected to the monitor the normal Mac sound controls are disabled. Is there a good way to detect first whether sound control is present (rather than catching exceptions) and also a good way to detect the change in sound output device? One of the things I'm trying to do is listen for changes in volume so would need to register and unregister when sound output device allows. thanks

yosemiteyss commented 1 year ago

It seems your monitor doesn't support volume control. Right now the plugin can only access the default audio output device. If you want to control another audio device, like switching from monitor to macbook speaker, you have to do it from OS settings.

A better approach would be controlling a specific output device through its device id. But it would take some times to implement on different desktop platforms.

melio-matt commented 1 year ago

I wasn't looking to control the output device only react to it changing and knowing its capabilities. Currently I only know there is no volume control when I ask for the current volume and an exception is thrown. It would be nicer if calling getVolume reported it wasn't available rather than getting an exception and I would then know not to register the volume listeners. Having a listener to know when the output device changes would be nice, but I could poll getVolume, handle the exception, and use this as my mechanism.

melio-matt commented 1 year ago

One thing that would be good would be to mention this on the readme page, could save someone else some time in wondering why it isn't working for them. Thanks