Skip to content

Commit

Permalink
android: add more audio stream types
Browse files Browse the repository at this point in the history
  • Loading branch information
yosemiteyss committed Apr 19, 2024
1 parent 6dd623d commit 5e67094
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 26 deletions.
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,16 @@ 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`.
- For more details,
visit [AudioManager](https://developer.android.com/reference/android/media/AudioManager)
- Supported streams:
- `AudioStream.accessibility`
- `AudioStream.alarm`
- `AudioStream.dtmf`
- `AudioStream.music`
- `AudioStream.notification`
- `AudioStream.ring`
- `AudioStream.system`
- `AudioStream.voiceCall`
- For more details, visit [AudioManager](https://developer.android.com/reference/android/media/AudioManager).

```dart
await FlutterVolumeController.setAndroidAudioStream(stream: AudioStream.system);
Expand All @@ -106,11 +112,15 @@ 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`
- Supported categories:
- `AudioSessionCategory.ambient`
- `AudioSessionCategory.multiRoute`
- `AudioSessionCategory.playAndRecord`
- `AudioSessionCategory.playback`
- `AudioSessionCategory.record`
- `AudioSessionCategory.soleAmbient`
- For more details,
visit [AVAudioSession.Category](https://developer.apple.com/documentation/avfaudio/avaudiosession/category)
visit [AVAudioSession.Category](https://developer.apple.com/documentation/avfaudio/avaudiosession/category).

```dart
await FlutterVolumeController.setIOSAudioSessionCategory(category: AudioSessionCategory.playback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@ package com.yosemiteyss.flutter_volume_controller
import android.media.AudioManager

enum class AudioStream {
VOICE_CALL,
SYSTEM,
RING,
ACCESSIBILITY,
ALARM,
DTMF,
MUSIC,
ALARM;
NOTIFICATION,
RING,
SYSTEM,
VOICE_CALL;

val streamType: Int
get() {
return when (this) {
VOICE_CALL -> AudioManager.STREAM_VOICE_CALL
SYSTEM -> AudioManager.STREAM_SYSTEM
RING -> AudioManager.STREAM_RING
MUSIC -> AudioManager.STREAM_MUSIC
ACCESSIBILITY -> AudioManager.STREAM_ACCESSIBILITY
ALARM -> AudioManager.STREAM_ALARM
DTMF -> AudioManager.STREAM_DTMF
MUSIC -> AudioManager.STREAM_MUSIC
NOTIFICATION -> AudioManager.STREAM_NOTIFICATION
RING -> AudioManager.STREAM_RING
SYSTEM -> AudioManager.STREAM_SYSTEM
VOICE_CALL -> AudioManager.STREAM_VOICE_CALL
}
}
}
32 changes: 22 additions & 10 deletions lib/src/audio_stream.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
/// Enum class mapped to Android audio stream types.
///
/// [AudioStream.voiceCall] refers to AudioManager.STREAM_VOICE_CALL.
/// [AudioStream.system] refers to AudioManager.STREAM_SYSTEM.
/// [AudioStream.ring] refers to AudioManager.STREAM_RING.
/// [AudioStream.music] refers to AudioManager.STREAM_MUSIC.
/// [AudioStream.alarm] refers to AudioManager.STREAM_ALARM.
enum AudioStream {
voiceCall,
system,
ring,
music,
/// Used to identify the volume of audio streams for accessibility prompts.
accessibility,

/// Used to identify the volume of audio streams for alarms.
alarm,

/// Used to identify the volume of audio streams for DTMF Tones.
dtmf,

/// Used to identify the volume of audio streams for music playback.
music,

/// Used to identify the volume of audio streams for notifications.
notification,

/// Used to identify the volume of audio streams for the phone ring.
ring,

/// Used to identify the volume of audio streams for system sounds.
system,

/// Used to identify the volume of audio streams for phone calls.
voiceCall,
}

0 comments on commit 5e67094

Please sign in to comment.