मुख्य कंटेंट तक स्किप करें

Equalizer सेट करें

Connected device से मिली equalizer settings UI में दिखाएँ और user द्वारा चुनी setting लागू करें।

आवश्यक शर्तें

  • Device connected और ready हो।
  • Device DeviceEqualizerAPI conform करता हो।
  • जहाँ संभव हो, device द्वारा returned setting ही उपयोग करें।

API Reference

Framework

AIBuds.xcframework

Import

Swift
import AIBuds
import AIBudsFoundation

Protocol की घोषणा

Equalizer operations DeviceEqualizerAPI में defined हैं।

Swift
/// The protocol for device API that supports equalizer.
protocol DeviceEqualizerAPI: DeviceAPI {
    /// All available preset and custom equalizer settings reported by the device.
    var allEQSettings: [EQSettingModel] { get }

    /// The currently active equalizer setting.
    var eqSetting: EQSettingModel? { get }

    /// Applies the specified equalizer setting to the device.
    /// - Parameters:
    ///   - equalizerSetting: The equalizer configuration to be applied.
    ///   - completion: A closure that is invoked when the operation completes.
    ///     - success: `true` if the setting was successfully applied; otherwise `false`.
    ///     - error: An `NSError` object if an error occurs during the operation; otherwise `nil`.
    func setEqualizer(
        _ equalizerSetting: EQSettingModel,
        completion: AIBudsCompletionHandler?
    )
}

Instance method

दी गई equalizer setting device पर लागू करता है।

Swift
/// Applies the specified equalizer setting to the device.
/// - Parameters:
///   - equalizerSetting: The equalizer configuration to be applied.
///   - completion: A closure that is invoked when the operation completes.
///     - success: `true` if the setting was successfully applied; otherwise `false`.
///     - error: An `NSError` object if an error occurs during the operation; otherwise `nil`.
func setEqualizer(
    _ equalizerSetting: EQSettingModel,
    completion: AIBudsCompletionHandler?
)

उपलब्ध parameters

ParameterTypeविवरण
equalizerSettingEQSettingModelलागू की जाने वाली device setting।
completionAIBudsCompletionHandler?Operation पूरा होने पर optional callback।

Callback parameters:

NameTypeविवरण
successBool / BOOLचुनी गई setting लागू हुई या नहीं।
errorNSError?Failure details; सफलता पर nil

Return value

Method सीधे value return नहीं करता। Result completion callback में मिलता है।

उपयोग के उदाहरण

Swift
import AIBuds
import AIBudsFoundation

guard let device = device as? DeviceEqualizerAPI else {
    print("Device does not support equalizer")
    return
}

guard let selectedSetting = device.allEQSettings.first else {
    print("The device did not provide an equalizer setting")
    return
}

device.setEqualizer(selectedSetting) { success, error in
    guard success else {
        print("Failed to apply equalizer: \(error?.localizedDescription ?? "Unknown error")")
        return
    }
    print("Equalizer applied: \(selectedSetting.name ?? "Unnamed setting")")
}

Custom settings

Connected device द्वारा reported custom slot उपयोग करें। उसका gains.count device-specific band count देता है, जबकि minimumGain और maximumGain, -12...12 dB की transport range define करते हैं। customSetting(index:gains:) zero-based slot को customModeStart से शुरू होने वाले mode में map करता है और invalid input पर nil लौटाता है।

Swift
// A returned custom setting identifies a slot and its supported band count.
guard let reportedSetting = device.allEQSettings.first(where: \.isCustom),
    let slot = reportedSetting.customIndex?.intValue
else {
    return
}

// Supply one gain per reported band. Every value must be within -12...12 dB.
let gains = Array(repeating: 0, count: reportedSetting.gains.count)
guard let customSetting = EQSettingModel.customSetting(index: slot, gains: gains) else {
    return
}

device.setEqualizer(customSetting, completion: nil)

defaultBandCount built-in presets का band count है। Connected device द्वारा reported अलग band count को इससे override न करें।

Error handling

success == false संभालें और उपलब्ध होने पर error दिखाएँ। Public API equalizer-specific error codes define नहीं करती।