搜索插件、代码仓与 APP 分类

插件详情v3.7.1

volume_controller

一个适用于多个平台的 Flutter 音量插件,用于控制系统音量。

AndroidiOSmacOSWindowsLinux
近 30 天下载
18.7万
喜欢数
132
Pub 分数
160

安装插件

flutter pub add volume_controller

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

volume_controller 包是一个跨平台的 Flutter 插件,可在 Android、iOS、macOS、Windows 和 Linux 上控制系统音量。它提供了一个简单的 API 来调整、静音和查询音量级别,非常适合媒体应用、音频工具或任何需要系统级音频控制的应用程序。该插件抽象了平台特定的实现,确保在各种设备上行为一致。它支持基于流的音量监控和直接音量操作。该插件设计时注重集成简便性,可无缝融入现有的 Flutter 项目。

适合场景

  • 媒体播放器音量控制
  • 音频应用系统集成
  • 可访问性工具
  • 音频功能的自动化测试
  • 系统级音量调整

主要特点

  • 跨平台支持(Android、iOS、macOS、Windows、Linux)
  • 音量调节和静音
  • 通过流实现实时音量监控
  • 简单、一致的 API
  • 原生音量控制的平台抽象

适合对象

  • 开发以音频为中心的应用程序的开发者
  • 需要系统音量访问权限的应用
  • 多平台音频工具
  • 测试跨操作系统的音频行为

使用建议

  • 需要适当的平台权限
  • 行为在不同操作系统之间可能略有差异
  • 限于系统音量(非应用特定)
  • 不适合低级别音频处理
  • 某些平台可能需要用户权限

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Volume Controller

pub package license

Control and observe the system volume on Android, iOS, macOS, Windows, and Linux.

Requirements

  • Flutter >=3.44.0
  • Dart ^3.12.0

The iOS plugin uses the scene lifecycle APIs introduced for Flutter plugins in Flutter 3.38.

Supported Platforms

Platform Supported
Android ✅
iOS ✅
macOS ✅
Windows ✅
Linux ✅

Notes

  • iOS volume control must be tested on a real device. The simulator does not support system volume control.
  • showSystemUI is supported on Android and iOS only.
  • Mute is not volume 0 on every platform:
    • Windows, macOS, Linux: system mute. Volume can stay non-zero while muted.
    • Android API 23+: STREAM_MUSIC mute (isStreamMute / ADJUST_MUTE).
    • Android API 21–22: mute sets volume to 0 and unmute restores the previous volume saved by the plugin.
    • iOS: there is no public system media mute API. isMuted() is volume == 0. setMute(true) sets volume to 0; setMute(false) restores the previous volume saved by the plugin. iOS 26 AVAudioSession.setOutputMuted is not used, because it mutes this app's audio session rather than the system volume.

Variables

ShowSystemUI

Show or hide the volume system UI. The default value is true. Supported on iOS and Android only.

VolumeController.instance.showSystemUI = true;

Functions

GetVolume

Get the current system volume.

double volume = await VolumeController.instance.getVolume();
SetVolume

Set the system volume. The input should be in the range 0.0 to 1.0.

await VolumeController.instance.setVolume(double volume);
AddListener

Add a listener to monitor system volume changes.

  • fetchInitialVolume: Send the current volume immediately. Defaults to true.
VolumeController.instance.addListener((volume) {
  // Do something with the volume
}, fetchInitialVolume: true);
RemoveListener

Remove the volume listener.

await VolumeController.instance.removeListener();
IsMuted

Check whether the system is muted.

bool isMuted = await VolumeController.instance.isMuted();
SetMute

Mute or unmute the system volume.

await VolumeController.instance.setMute(bool mute);

所属分类

源码仓库

使用此插件的项目