diff --git a/CHANGELOG.md b/CHANGELOG.md index a704c80..8f05172 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 8d145c7..eff00f7 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -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 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index f540f73..b422e9a 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -204,6 +204,7 @@ files = ( ); inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); name = "Thin Binary"; outputPaths = ( diff --git a/example/lib/main.dart b/example/lib/main.dart index f982f05..8b8e988 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -33,6 +33,14 @@ class _HomeState extends State { @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; @@ -279,4 +287,22 @@ class _HomeState extends State { ), ); } + + Future _loadIOSAudioSessionCategory() async { + final category = await FlutterVolumeController.getIOSAudioSessionCategory(); + if (category != null) { + setState(() { + _audioSessionCategory = category; + }); + } + } + + Future _loadAndroidAudioStream() async { + final audioStream = await FlutterVolumeController.getAndroidAudioStream(); + if (audioStream != null) { + setState(() { + _audioStream = _audioStream; + }); + } + } } diff --git a/example/pubspec.lock b/example/pubspec.lock index f171e6b..5c91b5c 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -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 diff --git a/ios/Classes/VolumeController.swift b/ios/Classes/VolumeController.swift index 01f48b3..a45f557 100644 --- a/ios/Classes/VolumeController.swift +++ b/ios/Classes/VolumeController.swift @@ -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 { @@ -79,7 +76,6 @@ class VolumeController { } func getAudioSessionCategory() throws -> AudioSessionCategory? { - try audioSession.setActive(true) return AudioSessionCategory.allCases.first { category in category.categoryType == audioSession.category } } diff --git a/pubspec.yaml b/pubspec.yaml index 9c40acc..cc549eb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: