Skip to content

Commit

Permalink
activate ambient audio session category
Browse files Browse the repository at this point in the history
  • Loading branch information
yosemiteyss committed Jul 4, 2023
1 parent df51b89 commit a4a0199
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
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
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

0 comments on commit a4a0199

Please sign in to comment.