一个 Flutter 插件,可在 Android、iOS、macOS、Windows 和 Linux 上实现对系统音量的控制,并实时监听音量变化。它提供了一致的 API 来调整音量级别,并响应用户操作或系统触发的音量调整。非常适合媒体应用、音频播放器或任何需要精确音量管理的应用程序。该插件抽象了平台特定的实现,确保跨平台兼容性,且设置简单。
适合场景
媒体播放器音量控制
实时音量监控
音频应用集成
系统级音量调整
跨平台音频应用
主要特点
跨平台音量控制
音量更改事件监听器
平台无关的 API
支持 Android、iOS、macOS、Windows 和 Linux
通过 pub add 的简单集成
适合对象
音频和媒体应用
需要系统音量访问权限的应用
面向多平台的开发者
交互式音频体验
需要音量反馈的应用程序
使用建议
某些操作系统需要特定平台的权限
仅限系统音量(非应用特定)
行为在不同平台之间可能略有差异
不适合低级别音频处理
可能需要在桌面平台上进行额外配置
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
Flutter Volume Controller
A Flutter plugin to control system volume and listen for volume changes on different platforms.
Features
Control system and media volumes.
Listen for volume changes.
Platform Support
✅ Android
✅ iOS
✅ macOS
✅ Windows
✅ Linux
✅ ohos
Swift Package Manager Support
This plugin supports Swift Package Manager (SPM) on Apple platforms:
On iOS, volume control uses MPVolumeView internally which does not works on simulator. Please uses physical
device for testing.
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.
Audio devices without volume control
On desktop platforms like Windows and Linux, you may encounter PlatformException if the default
audio device doesn't support volume control, like an external monitor.
Controlling Android volume slider UI
Currently there is no trivial way to control the volume slider invoked by physical buttons on
Android in plugin level. You may override FlutterActivity::onKeyDown to customize the buttons action.