volume 0.1.0

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.

0.1.0 #

Just Version Upgrade

0.0.8 #

Added License.

0.0.7 #

Little change in docs.

0.0.6 #

Added volUp button press and volDown button press from system_shortcuts plugin.

0.0.5 #

Updated the dartDoc documentation in Volume.dart class.

0.0.4 #

Updated description

0.0.3 #

Example readme update.

0.0.2 #

Updated Readme.md and removed unnecessary print statements

0.0.1 #

Control Android Volumes programatically.

example/README.md

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:volume/volume.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

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

  @override
  void initState() {
    super.initState();
    audioManager = AudioManager.STREAM_SYSTEM;
    initPlatformState();
    updateVolumes();
  }

  Future<void> initPlatformState() async {
    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);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              DropdownButton(
                value: audioManager,
                items: [
                  DropdownMenuItem(
                    child: Text("In Call Volume"),
                    value: AudioManager.STREAM_VOICE_CALL,
                  ),
                  DropdownMenuItem(
                    child: Text("System Volume"),
                    value: AudioManager.STREAM_SYSTEM,
                  ),
                  DropdownMenuItem(
                    child: Text("Ring Volume"),
                    value: AudioManager.STREAM_RING,
                  ),
                  DropdownMenuItem(
                    child: Text("Media Volume"),
                    value: AudioManager.STREAM_MUSIC,
                  ),
                  DropdownMenuItem(
                    child: Text("Alarm volume"),
                    value: AudioManager.STREAM_ALARM,
                  ),
                  DropdownMenuItem(
                    child: Text("Notifications Volume"),
                    value: AudioManager.STREAM_NOTIFICATION,
                  ),
                ],
                isDense: true,
                onChanged: (AudioManager aM) async {
                  print(aM.toString());
                  setState(() {
                    audioManager = aM;
                  });
                  await Volume.controlVolume(aM);
                },
              ),
              (currentVol != null || maxVol != null)
                  ? Slider(
                      value: currentVol / 1.0,
                      divisions: maxVol,
                      max: maxVol / 1.0,
                      min: 0,
                      onChanged: (double d) {
                        setVol(d.toInt());
                        updateVolumes();
                      },
                    )
                  : Container(),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  volume: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:volume/volume.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
81
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
88
Learn more about scoring.

We analyzed this package on Sep 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/volume.dart.

Run flutter format to format lib/volume.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (system_shortcuts).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
system_shortcuts ^0.0.4 0.0.7 0.1.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8