Wednesday, October 28, 2026
HomeiOS Developmentios - Audio from haptic engine solely taking part in by means...

ios – Audio from haptic engine solely taking part in by means of audio system

[ad_1]

I am engaged on an app that makes use of CoreHaptics to play a synchronised sample of vibrations and audio.
The issue is that the audio solely will get performed by means of the iPhones audio system (if the mute swap is just not turned on). As quickly as I join my AirPods to the cellphone the audio stops taking part in, however the haptics proceed.

My code appears one thing like this:

let engine = CHHapticEngine()
...
var occasions = [CHHapticEvent]()
...
let quantity: Float = 1
let decay: Float = 0.5
let sustained: Float = 0.5
let audioParameters = [
    CHHapticEventParameter(parameterID: .audioVolume, value: volume),
    CHHapticEventParameter(parameterID: .decayTime, value: decay),
    CHHapticEventParameter(parameterID: .sustained, value: sustained)
]
let breathingTimes = pacer.breathingTimeInSeconds
let combinedTimes = breathingTimes.inhale + breathingTimes.exhale
let audioEvent = CHHapticEvent(
    audioResourceID: selectedAudio,
    parameters: audioParameters,
    relativeTime: 0,
    period: combinedTimes
)
occasions.append(audioEvent)
...
let sample = attempt CHHapticPattern(occasions: occasions, parameterCurves: [])
let participant = attempt engine.makeAdvancedPlayer(with: sample)
...
attempt participant.begin(atTime: CHHapticTimeImmediate)

My concept to activate an audio session earlier than the participant begins, to point to the system that audio is performed, additionally did not modified the result:

attempt AVAudioSession.sharedInstance().setActive(true)

Is there a distinct solution to route the audio from CoreHaptics to a distinct output apart from the built-in audio system?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments