Skip to content

Commit

Permalink
Merge pull request #57 from yosemiteyss/feat/merge-dev-to-main
Browse files Browse the repository at this point in the history
merge dev to main
  • Loading branch information
yosemiteyss authored Jul 4, 2023
2 parents df51b89 + 4373aec commit 4b0e99d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.2.7
* Fixed audio session not activated with ambient state on iOS.

## 1.2.6
* Added volume slider example.
* Updated documentation.
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_volume_controller: e4d5832f08008180f76e30faf671ffd5a425e529
integration_test: a1e7d09bd98eca2fc37aefd79d4f41ad37bdbbe5
integration_test: 13825b8a9334a850581300559b8839134b124670

PODFILE CHECKSUM: ec7bdfce9f82e8314b94d9cd1cfee2974a0e1c97

COCOAPODS: 1.11.3
COCOAPODS: 1.12.1
1 change: 1 addition & 0 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand Down
26 changes: 26 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class _HomeState extends State<Home> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (Platform.isIOS) {
await _loadIOSAudioSessionCategory();
}
if (Platform.isAndroid) {
await _loadAndroidAudioStream();
}
});
FlutterVolumeController.addListener((volume) {
setState(() {
_currentVolume = volume;
Expand Down Expand Up @@ -279,4 +287,22 @@ class _HomeState extends State<Home> {
),
);
}

Future<void> _loadIOSAudioSessionCategory() async {
final category = await FlutterVolumeController.getIOSAudioSessionCategory();
if (category != null) {
setState(() {
_audioSessionCategory = category;
});
}
}

Future<void> _loadAndroidAudioStream() async {
final audioStream = await FlutterVolumeController.getAndroidAudioStream();
if (audioStream != null) {
setState(() {
_audioStream = _audioStream;
});
}
}
}
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.2.6"
version: "1.2.7"
fuchsia_remote_debug_protocol:
dependency: transitive
description: flutter
Expand Down
10 changes: 3 additions & 7 deletions ios/Classes/VolumeController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,33 @@ class VolumeController {
}

func getVolume() throws -> Float {
try audioSession.setActive(true)
try audioSession.activate(with: VolumeController.defaultCategory)
let volume = audioSession.outputVolume
return volume
}

func setVolume(_ volume: Double, showSystemUI: Bool) throws {
try audioSession.setActive(true)
setShowSystemUI(showSystemUI)
volumeView.setVolume(volume)
}

func raiseVolume(_ step: Double?, showSystemUI: Bool) throws {
try audioSession.setActive(true)
setShowSystemUI(showSystemUI)
volumeView.raiseVolume(step ?? VolumeController.defaultStep)
}

func lowerVolume(_ step: Double?, showSystemUI: Bool) throws {
try audioSession.setActive(true)
setShowSystemUI(showSystemUI)
volumeView.lowerVolume(step ?? VolumeController.defaultStep)
}

func getMute() throws -> Bool {
try audioSession.setActive(true)
try audioSession.activate(with: VolumeController.defaultCategory)
return audioSession.outputVolume == 0
}

func setMute(_ isMuted: Bool, showSystemUI: Bool) throws {
try audioSession.setActive(true)
try audioSession.activate(with: VolumeController.defaultCategory)

// Save current volume level before mute.
if isMuted {
Expand All @@ -79,7 +76,6 @@ class VolumeController {
}

func getAudioSessionCategory() throws -> AudioSessionCategory? {
try audioSession.setActive(true)
return AudioSessionCategory.allCases.first { category in category.categoryType == audioSession.category }
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_volume_controller
description: A Flutter plugin to control system volume and listen for volume changes on different platforms.
version: 1.2.6
version: 1.2.7
homepage: https://github.com/yosemiteyss/flutter_volume_controller

environment:
Expand Down

0 comments on commit 4b0e99d

Please sign in to comment.