搜尋套件、儲存庫與 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);

所屬分類

原始碼儲存庫

使用此套件的專案