패키지, 저장소 및 앱 카테고리 검색

패키지 상세v2.0.2

flutter_volume_controller

다양한 플랫폼에서 시스템 볼륨을 제어하고 볼륨 변경 사항을 수신하는 데 사용할 수 있는 Flutter 플러그인입니다.

AndroidiOSmacOSWindowsLinux
30일 다운로드
6.1만
좋아요
76
Pub 점수
150

패키지 설치

flutter pub add flutter_volume_controller

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

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.

pub package

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:

  • ✅ iOS
  • ✅ macOS

Example

Custom Volume Slider

Usage

Control System UI Visibility
  • Set to true to display system volume slider when changing volume.
  • This setting only works on Android, iOS and ohos.
  • Note: this setting doesn't control the volume slider invoked by physical buttons on Android.
await FlutterVolumeController.updateShowSystemUI(true);
Get Volume
final volume = await FlutterVolumeController.getVolume();
Set Volume
await FlutterVolumeController.setVolume(0.5);
Increase Volume
  • On Android, Windows and ohos, when step is set to null, it will use 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, Windows and ohos, when step is set to null, it will use 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, iOS and ohos, 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, iOS and ohos, 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 Audio Stream on Android
  • Adjusts to the audio stream whose volume should be changed by the hardware volume controls.
  • Supported streams: AudioStream.voiceCall, AudioStream.system, AudioStream.ring , AudioStream.music, AudioStream.alarm, AudioStream.notification.
  • For more details, visit AudioManager
await FlutterVolumeController.setAndroidAudioStream(stream: AudioStream.system);
Get Audio Stream on Android
  • Get the current audio stream on Android.
final stream = await FlutterVolumeController.getAndroidAudioStream();
Set Audio Session Category on iOS
  • Adjusts to a different set of audio behaviors.
  • Supported categories: AudioSessionCategory.ambient, AudioSessionCategory.multiRoute , AudioSessionCategory.playAndRecord, AudioSessionCategory.playback , AudioSessionCategory.record, AudioSessionCategory.soleAmbient
  • For more details, visit AVAudioSession.Category
await FlutterVolumeController.setIOSAudioSessionCategory(category: AudioSessionCategory.playback);
Get Audio Session Category on iOS
  • Get the current audio session category on iOS.
final category = await FlutterVolumeController.getIOSAudioSessionCategory();
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();
  FlutterVolumeController.addListener(
    (volume) {
      debugPrint('Volume changed: $volume');
    },
  );
}

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

Notes

Volume controls doesn't work on iOS simulator
  • 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.
HarmonyOS compatible SDK version

Having Bugs?

  • This package is under active development. If you find any bug, please create an issue on GitHub.

Support

"Buy Me A Coffee"

카테고리

의존성

의존성 목록 1 개

소스 저장소

이 패키지를 사용하는 프로젝트