call_sound_controller 0.0.1 copy "call_sound_controller: ^0.0.1" to clipboard
call_sound_controller: ^0.0.1 copied to clipboard

PlatformAndroid

A Flutter plugin to control the call volume on Android. Get current, max volume and set volume programmatically.

Call Sound Controller #

A Flutter plugin to control the call volume on Android devices. This plugin allows you to get the current call volume, get the maximum possible call volume, and set the call volume to a specific level.

Features #

  • Get Current Call Volume: Retrieve the current volume level of the voice call stream.
  • Get Max Call Volume: Retrieve the maximum volume level allowed for the voice call stream.
  • Set Call Volume: Set the volume of the voice call stream to a specific integer value.

Platform Support #

Platform Support
Android
iOS
Web
Windows
MacOS
Linux

Installation #

Add call_sound_controller as a dependency in your pubspec.yaml file:

dependencies:
  call_sound_controller: ^0.0.1

Usage #

Import the package in your Dart code:

import 'package:call_sound_controller/call_sound_controller.dart';

Get Max Volume #

Before setting the volume, it's good practice to know the maximum volume level supported by the device.

int? maxVolume = await CallSoundController.getMaxVolume();
print('Max Volume: $maxVolume');

Get Current Volume #

You can get the current volume level.

int? currentVolume = await CallSoundController.getVolume();
print('Current Volume: $currentVolume');

Set Volume #

Set the volume to a value between 0 and the maximum volume.

// Set volume to 5
await CallSoundController.setVolume(5);

Example #

Here is a simple example of how to use the plugin in a Flutter app:

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Call Sound Controller')),
        body: Center(
          child: ElevatedButton(
            onPressed: () async {
              // Get max volume
              final max = await CallSoundController.getMaxVolume();
              // Set volume to half of max
              if (max != null) {
                await CallSoundController.setVolume(max ~/ 2);
              }
            },
            child: const Text('Set Volume to 50%'),
          ),
        ),
      ),
    );
  }
}

Permissions #

This plugin uses the Context.AUDIO_SERVICE to control the volume. On most Android devices, no special permissions are required to modify the STREAM_VOICE_CALL volume if your app has audio focus or is in a call, but generally, MODIFY_AUDIO_SETTINGS permission might be beneficial in some contexts. However, for basic usage as tested, it works without explicit manifest permissions for volume control.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

1
likes
150
points
79
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to control the call volume on Android. Get current, max volume and set volume programmatically.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on call_sound_controller

Packages that implement call_sound_controller