equalizer 0.0.2+1

  • Readme
  • Changelog
  • Example
  • Installing
  • new71

equalizer #

A Flutter plugin to open the device equalizer. You can also create a custom equalizer for Android.

Currently, supported on Android only. Need help for iOS contributions.

Example

Android Setup #

Edit your project's AndroidManifest.xml file to declare the permission to modify audio settings when creating a custom equalizer.

<manifest>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <application...>
    
    ...
    </application...>
</manifest>

Example #

// Import package
import 'package:equalizer/equalizer.dart';

// Open device equalizer
Equalizer.open(audioSessionId);

// Set or remove audioSessionId.
Equalizer.setAudioSessionId(audioSessionId);
Equalizer.removeAudioSessionId(audioSessionId);

You can retrieve audioSessionId on android from MediaPlayer. Info on how to do this can be found in openEqualizer docs.

Custom Equalizer Example #

Initialize the equalizer. Recommended to perform inside initState

Equalizer.init(audioSessionId);

Enable the equalizer as follows.

Equalizer.setEnabled(true);

Now you can query the methods.

await Equalizer.getBandLevelRange(); // provides band level range in dB.

await Equalizer.getBandLevel(bandId);
Equalizer.setBandLevel(bandId,bandLevel);

await Equalizer.getCenterBandFreqs(); // provides the center freqs in milliHertz.

await Equalizer.getPresetNames(); // returns presets that are available on device
Equalizer.setPreset(presetName);

Finally, remember to release resources. Recommended to perform inside dispose

Equalizer.release();

TODO #

  • Add iOS support.

0.0.2+1 #

  • Refactored example.
  • Removed onPresetChanged listener.

0.0.2 #

  • Implemented custom equalizer for Android.
  • Equalizer.openEqualizer(audioSessionId) has been simplified to Equalizer.open(audioSessionId)
  • Readme has been updated to include usage for custom equalizer.
  • Example has been updated to showcase custom equalizer.

0.0.1+1 #

  • Update description & Readme.

0.0.1 #

  • Initial release.

example/lib/main.dart

import 'dart:async';

import 'package:equalizer/equalizer.dart';
import 'package:flutter/material.dart';
import 'package:flutter_xlider/flutter_xlider.dart';

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

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

class _MyAppState extends State<MyApp> {
  bool enableCustomEQ = false;

  @override
  void initState() {
    super.initState();
    Equalizer.init(0);
  }

  @override
  void dispose() {
    Equalizer.release();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Equalizer example'),
        ),
        body: ListView(
          children: [
            SizedBox(height: 10.0),
            Center(
              child: FlatButton.icon(
                icon: Icon(Icons.equalizer),
                label: Text('Open device equalizer'),
                color: Colors.blue,
                textColor: Colors.white,
                onPressed: () => Equalizer.open(0),
              ),
            ),
            SizedBox(height: 10.0),
            Container(
              color: Colors.grey.withOpacity(0.1),
              child: SwitchListTile(
                title: Text('Custom Equalizer'),
                value: enableCustomEQ,
                onChanged: (value) {
                  Equalizer.setEnabled(value);
                  setState(() {
                    enableCustomEQ = value;
                  });
                },
              ),
            ),
            FutureBuilder<List<int>>(
              future: Equalizer.getBandLevelRange(),
              builder: (context, snapshot) {
                return snapshot.connectionState == ConnectionState.done
                    ? CustomEQ(enableCustomEQ, snapshot.data)
                    : CircularProgressIndicator();
              },
            ),
          ],
        ),
      ),
    );
  }
}

class CustomEQ extends StatefulWidget {
  const CustomEQ(this.enabled, this.bandLevelRange);

  final bool enabled;
  final List<int> bandLevelRange;

  @override
  _CustomEQState createState() => _CustomEQState();
}

class _CustomEQState extends State<CustomEQ> {
  double min, max;
  String _selectedValue;
  Future<List<String>> fetchPresets;

  @override
  void initState() {
    super.initState();
    min = widget.bandLevelRange[0].toDouble();
    max = widget.bandLevelRange[1].toDouble();
    fetchPresets = Equalizer.getPresetNames();
  }

  @override
  Widget build(BuildContext context) {
    int bandId = 0;

    return FutureBuilder<List<int>>(
      future: Equalizer.getCenterBandFreqs(),
      builder: (context, snapshot) {
        return snapshot.connectionState == ConnectionState.done
            ? Column(
                children: [
                  Row(
                    children: snapshot.data
                        .map((freq) => _buildSliderBand(freq, bandId++))
                        .toList(),
                  ),
                  Divider(),
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: _buildPresets(),
                  ),
                ],
              )
            : CircularProgressIndicator();
      },
    );
  }

  Widget _buildSliderBand(int freq, int bandId) {
    return Column(
      children: [
        SizedBox(
          height: 250.0,
          child: FutureBuilder<int>(
            future: Equalizer.getBandLevel(bandId),
            builder: (context, snapshot) {
              return FlutterSlider(
                disabled: !widget.enabled,
                axis: Axis.vertical,
                rtl: true,
                min: min,
                max: max,
                values: [snapshot.hasData ? snapshot.data.toDouble() : 0],
                onDragCompleted: (handlerIndex, lowerValue, upperValue) {
                  Equalizer.setBandLevel(bandId, lowerValue.toInt());
                },
              );
            },
          ),
        ),
        Text('${freq ~/ 1000} Hz'),
      ],
    );
  }

  Widget _buildPresets() {
    return FutureBuilder<List<String>>(
      future: fetchPresets,
      builder: (context, snapshot) {
        if (snapshot.hasData) {
          final presets = snapshot.data;
          if (presets.isEmpty) return Text('No presets available!');
          return DropdownButtonFormField(
            decoration: InputDecoration(
              labelText: 'Available Presets',
              border: OutlineInputBorder(),
            ),
            value: _selectedValue,
            onChanged: widget.enabled
                ? (String value) {
                    Equalizer.setPreset(value);
                    setState(() {
                      _selectedValue = value;
                    });
                  }
                : null,
            items: presets.map((String value) {
              return DropdownMenuItem<String>(
                value: value,
                child: Text(value),
              );
            }).toList(),
          );
        } else if (snapshot.hasError)
          return Text(snapshot.error);
        else
          return CircularProgressIndicator();
      },
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  equalizer: ^0.0.2+1

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:equalizer/equalizer.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
47
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]
71
Learn more about scoring.

We analyzed this package on Jul 10, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:equalizer/equalizer.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:equalizer/equalizer.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:equalizer/equalizer.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:equalizer/equalizer.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • equalizer that is a package requiring null.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test