Coder Social home page Coder Social logo

derjojo11 / flutter_volume_controller Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yosemiteyss/flutter_volume_controller

0.0 0.0 0.0 349 KB

License: MIT License

Ruby 1.98% C++ 47.03% C 2.44% Objective-C 0.36% Kotlin 6.29% Dart 6.28% Swift 17.68% CMake 17.94%

flutter_volume_controller's Introduction

Flutter Volume Controller

A Flutter plugin to control system volume and listen for volume changes on different platforms.

pub package

Features

  • Control system and media volumes.
  • Listen for volume changes.

Platform Support

  • ✅ Android
  • ✅ iOS
  • ✅ macOS
  • ✅ Windows
  • ✅ Linux

Usage

Control System UI Visibility

  • Set to true to display system volume slider when changing volume.
  • This settings only works on Android and iOS.
FlutterVolumeController.showSystemUI = true;

Get Volume

final volume = await FlutterVolumeController.getVolume();

Set Volume

await FlutterVolumeController.setVolume(0.5);

Increase Volume

  • On Android and Windows, when step is set to null, it will uses the default system stepping value.
  • On iOS, macOS, Linux, if step is undefined, the default stepping value is set to 0.15.
await FlutterVolumeController.raiseVolume(0.2);
await FlutterVolumeController.raiseVolume(null);

Decrease Volume

  • On Android and Windows, when step is set to null, it will uses the default system stepping value.
  • On iOS, macOS, Linux, if step is undefined, the default stepping value is set to 0.15.
await FlutterVolumeController.lowerVolume(0.2);
await FlutterVolumeController.lowerVolume(null);

Check Mute

  • On Android and iOS, we check if the current volume level is already dropped to zero.
  • On macOS, Windows, Linux, we check if the mute switch is turned on.
final isMuted = await FlutterVolumeController.getMute();

Set Mute

  • On Android and iOS, we either set the volume to zero or revert to the previous level.
  • On macOS, Windows, Linux, we control the mute switch. Volume will be restored once it's unmuted.
await FlutterVolumeController.setMute(true);
await FlutterVolumeController.setMute(false);

Toggle Mute

await FlutterVolumeController.toggleMute();

Set the Audio Stream on Android

  • Support two types of audio stream: AudioStream.system, AudioStream.music.
  • This method should be called to ensure that volume controls adjust the correct stream.
await FlutterVolumeController.setAndroidAudioStream(stream: AudioStream.system);
await FlutterVolumeController.setAndroidAudioStream(stream: AudioStream.music);

Listen for Volume Changes

  • Use emitOnStart to control whether volume level should be emitted immediately right after the listener is attached.
@override
void initState() {
  super.initState();
  // Ensure music stream in being controlled.
  FlutterVolumeController.setAndroidAudioStream(stream: AudioStream.music);
  FlutterVolumeController.addListener(
    (volume) {
      debugPrint('Volume changed: $volume');
    },
  );
}

@override
void dispose() {
  FlutterVolumeController.removeListener();
  super.dispose();
}

Notes

Fine-grained volume control

  • Due to platform and device difference, it's normal that volume level could not be controlled precisely. For example, Android supports only 15 volume steps by default, the volume after being set would be a rounded off value.

Having Bugs?

  • This package is under active development. If you find any issue, please free to report them.

flutter_volume_controller's People

Contributors

yosemiteyss avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.