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

वॉल्यूम सेट करें

कोई निश्चित वॉल्यूम स्तर सेट करें, लिखे जा सकने वाले तीनों channels को एक साथ बदलें, या किसी समर्थित channel को डिवाइस द्वारा तय एक step बढ़ाएँ या घटाएँ।

आवश्यकताएँ

  • डिवाइस कनेक्टेड और ready है।
  • डिवाइस DeviceVolumeControlAPI के अनुरूप है।
  • volumeSetCapability का मान .none नहीं है।
  • दिए गए वॉल्यूम मान 0 से 100 के बीच हैं।

API संदर्भ

Framework

AIBuds.xcframework

Import

Swift
import AIBuds

प्रोटोकॉल

Methods DeviceVolumeControlAPI में परिभाषित हैं।

Swift
/// The protocol for device volume control API.
protocol DeviceVolumeControlAPI: DeviceAPI {
    /// Sets the volume for the specified type.
    /// - Parameters:
    ///   - volumeType: The volume type to adjust.
    ///   - value: the volume value (0–100)
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func setVolume(
        _ volumeType: DeviceVolumeType,
        value: Int,
        completion: AIBudsCompletionHandler?
    )

    /// Sets multiple volume levels at once.
    /// - Parameters:
    ///   - systemPrompt: The system prompt volume level. (0–100)
    ///   - media: The media playback volume level. (0–100)
    ///   - call: The call volume level. (0–100)
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func setVolumes(
        systemPrompt: Int,
        media: Int,
        call: Int,
        completion: AIBudsCompletionHandler?
    )

    /// Increases the specified volume channel by one step.
    /// - Parameters:
    ///   - volumeType: The volume channel to adjust.
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func volumeUp(
        _ volumeType: DeviceVolumeType,
        completion: AIBudsCompletionHandler?
    )

    /// Decreases the specified volume channel by one step.
    /// - Parameters:
    ///   - volumeType: The volume channel to adjust.
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func volumeDown(
        _ volumeType: DeviceVolumeType,
        completion: AIBudsCompletionHandler?
    )
}

Instance विधियाँ

Methodउद्देश्य
setVolumeकिसी समर्थित channel को निश्चित मान पर सेट करता है।
setVolumessystem-prompt, media और call के मान एक साथ सेट करता है।
volumeUpसमर्थित channel को डिवाइस के तय एक step से बढ़ाता है।
volumeDownसमर्थित channel को डिवाइस के तय एक step से घटाता है।

पैरामीटर

ParameterTypeविवरण
volumeTypeDeviceVolumeType.systemPrompt, .media या .call
valueInt / NSInteger0 से 100 तक निश्चित स्तर।
systemPromptInt / NSInteger0 से 100 तक system-prompt स्तर।
mediaInt / NSInteger0 से 100 तक media-playback स्तर।
callInt / NSInteger0 से 100 तक in-call स्तर।
completionAIBudsCompletionHandler?Command समाप्त होने पर चलने वाला optional callback।

Callback पैरामीटर:

नामTypeविवरण
successBool / BOOLCommand सफल हुआ या नहीं।
errorNSError?विफलता का विवरण; सफलता पर nil

Return मान

ये methods सीधे कोई मान return नहीं करते।

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

एक Channel सेट करें

Swift
import AIBuds

guard let device = device as? DeviceVolumeControlAPI,
    device.volumeSetCapability != .none
else {
    print("Volume setting is unavailable")
    return
}

device.setVolume(.media, value: 60) { success, error in
    guard success else {
        print("Failed to set media volume: \(error?.localizedDescription ?? "Unknown error")")
        return
    }
    print("Media volume updated")
}

तीनों Channels एक साथ सेट करें

Swift
device.setVolumes(
    systemPrompt: 50,
    media: 60,
    call: 70
) { success, error in
    if !success {
        print(error?.localizedDescription ?? "Volume update failed")
    }
}

त्रुटि प्रबंधन

Call करने से पहले capability और स्पष्ट ranges validate करें। UI अपडेट करने से पहले success जाँचें और विफलता के लिए error उपयोग करें। Public contract के अनुसार API out-of-range values को clamp नहीं करता।

श्रेष्ठ अभ्यास

  1. Sliders को Debounce करें: SDK Demo निश्चित मान भेजने से पहले slider movement के बाद थोड़ी देर प्रतीक्षा करता है।
  2. Buttons के लिए Step APIs उपयोग करें: Step size डिवाइस को चुनना हो तो volumeUp और volumeDown उपयोग करें।
  3. Local Playback Write का भ्रम न दें: मौजूदा कोई setter local-playback value स्वीकार नहीं करता।
  4. पुष्ट स्थिति Refresh करें: सफलता के बाद volumesInfo या didVolumesChanged उपयोग करें।

नोट्स

  • लिखे जा सकने वाले तीन DeviceVolumeType cases system prompt, media और call हैं।
  • SDK में public write API आने तक local-playback volume read-only रहेगा; support जुड़ने पर यह पेज अपडेट करें।