Reputation: 85
i have 2 issues regarding the weird sounds in audiokit. let me explain it to you.
my app has a framework that is using audio permissions. for playing and recording already.
i tried 3 things. 1st approach. i have added a new feature using the audio-kit. when i start the audio-kit for the first time its perfectly working. but when i go to other screen and give permission to other framework the other framework works fine but when i came back to audio-kit the volume is too low. it seems to be cut by 50% and i cannot boost it back to 100%.
to bypass this i thought i have to stop the audio-kit and start it again when i have to use it. but weird stuff happened.
2nd approach. if i stop the audio kit to before using other-framework and comeback to audio-kit and restart it again, it creates weird buzzing sounds on playing sound and on stopping sound.
3rd approach. i used a sample code from "MetronomeSamplerSync". i used a sample code for metronome app. and on play i start the audio-kit and on stop i stop the audio-kit. and if produces the same issue of weird sound.
here is the sample code.
func startStopAction(met: AKSamplerMetronome, otherMet: AKSamplerMetronome) -> (AKButton) -> Void {
return { button in
// Stop if playing, Start if not playing.
if met.isPlaying {
met.stop()
do {
try AudioKit.stop()
} catch {
AKLog("AudioKit did not stop!")
}
} else {
//If other metronome is playing, sync to it, else just play.
if otherMet.isPlaying {
let now = AVAudioTime(hostTime: mach_absolute_time())
let beatAtNow = otherMet.beatTime(at: now)
met.setBeatTime(beatAtNow, at: now)
} else {
do {
try AudioKit.start()
} catch {
AKLog("AudioKit did not start!")
}
met.play()
}
}
button.title = met.isPlaying ? "Stop" : "Play"
}
}
Upvotes: 2
Views: 646
Reputation: 85
i was having the weird sound issue. and i fixed the issue by assigning the audio files again to metronome. there was no weird sound anymore and no more volume cut down. hope it will help all.
Upvotes: 1
Reputation: 3414
I've had the same issue (audiokit-volume cut by 50%). I had to remove the following lines in my other code:
let session = AVAudioSession.sharedInstance()
do {
// Configure the audio session for movie playback
try session.setCategory(AVAudioSessionCategoryPlayback,
mode: AVAudioSessionModeMeasurement,
options: [])
My guess is that the session categories have to be set very carefully and best would be if your other framework and AudioKit use the same AVAudioSession set up only once. Hope this helps.
Upvotes: 1