Skip to content

Now you can change android volumes in Flutter. You can change MEDIA volume, NOTIFICATION volume, RING Volume, VOICE CALL Volume, ALARM Volume and SYSTEM Volume. This is exclusively for android right now because I don't have max to do the IOS coding and I don't have experience in IOS coding as well. Pull requests for IOS Implementation are welcome.

License

Notifications You must be signed in to change notification settings

lbx-ai/Volume_Flutter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

volume

Controll Volume in Android programatically. No IOS Implementation yet . Pull Request for ios implementation are welcome.

Streams

AudioManager.STREAM_VOICE_CALL       -> Controll IN CALL Volume
AudioManager.STREAM_SYSTEM           -> Controll SYSTEM Volume
AudioManager.STREAM_RING             -> Controll RINGER Volume
AudioManager.STREAM_MUSIC            -> Controll MEDIA Volume
AudioManager.STREAM_ALARM            -> Controll ALARM Volume
AudioManager.STREAM_NOTIFICATION     -> Controll NOTIFICATION Volume

Functions and getters

Volume Buttons will affect this volume when in app

await Volume.controlVolume(AudioManager audioManager); // pass any stream as parameter

Returns maximum possible volume in integers

await Volume.getMaxVol; // returns an integer

Returns current volume level in integers

await Volume.getVol;// returns an integer

Set volume for the stream passed to controlVolume() function

await Volume.setVol(int i); // Max value of i is less than Volume.getMaxVol

Press Volume Up button programatically

Volume.volUp(); // press volUp key.

Press Volume Down button programatically

Volume.volDown(); // press volDown key.

Usage

class _MyAppState extends State<MyApp> {
  int maxVol, currentVol;

  @override
  void initState() {
    super.initState();
    // Make this call in initState() function in the root widgte of your app
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    // pass any stream as parameter as per requirement
    await Volume.controlVolume(AudioManager.STREAM_SYSTEM);
  }

  updateVolumes() async {
    // get Max Volume
    maxVol = await Volume.getMaxVol;
    // get Current Volume
    currentVol = await Volume.getVol;
    setState(() {});
  }

  setVol(int i) async {
    await Volume.setVol(i);
  }
  // To implement the volume Up and volume Down button press programatically.
  
  FlatButton(
    child: Text("Vol Up"),
    onPressed: (){
      Volume.volUp();// Consecutively increasing the volume by 1 unit.
      updateVolumes();
    },
  ),
  FlatButton(
    child: Text("Vol Down"),
    onPressed: (){
      Volume.volDown();// Consecutively decrease the volume by 1 unit.
      updateVolumes();
    },
  )

Getting Started

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

About

Now you can change android volumes in Flutter. You can change MEDIA volume, NOTIFICATION volume, RING Volume, VOICE CALL Volume, ALARM Volume and SYSTEM Volume. This is exclusively for android right now because I don't have max to do the IOS coding and I don't have experience in IOS coding as well. Pull requests for IOS Implementation are welcome.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 49.6%
  • Ruby 19.9%
  • Java 19.6%
  • Objective-C 7.4%
  • Swift 3.5%