161847f8eSopenharmony_ci/*
261847f8eSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
461847f8eSopenharmony_ci * you may not use this file except in compliance with the License.
561847f8eSopenharmony_ci * You may obtain a copy of the License at
661847f8eSopenharmony_ci *
761847f8eSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
861847f8eSopenharmony_ci *
961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and
1361847f8eSopenharmony_ci * limitations under the License.
1461847f8eSopenharmony_ci */
1561847f8eSopenharmony_ci
1661847f8eSopenharmony_ci/**
1761847f8eSopenharmony_ci * @file
1861847f8eSopenharmony_ci * @kit AudioKit
1961847f8eSopenharmony_ci */
2061847f8eSopenharmony_ci
2161847f8eSopenharmony_ciimport type { Callback } from './@ohos.base';
2261847f8eSopenharmony_ciimport type audio from './@ohos.multimedia.audio';
2361847f8eSopenharmony_ci
2461847f8eSopenharmony_ci/**
2561847f8eSopenharmony_ci * Provides audio haptic collaborative play interfaces.
2661847f8eSopenharmony_ci *
2761847f8eSopenharmony_ci * @namespace audioHaptic
2861847f8eSopenharmony_ci * @syscap SystemCapability.Multimedia.AudioHaptic.Core
2961847f8eSopenharmony_ci * @since 11
3061847f8eSopenharmony_ci */
3161847f8eSopenharmony_cideclare namespace audioHaptic {
3261847f8eSopenharmony_ci  /**
3361847f8eSopenharmony_ci   * Obtains an {@link AudioHapticManager} instance. This object is singleton in one process.
3461847f8eSopenharmony_ci   * @returns { AudioHapticManager } AudioHapticManager instance.
3561847f8eSopenharmony_ci   * @syscap SystemCapability.Multimedia.AudioHaptic.Core
3661847f8eSopenharmony_ci   * @since 11
3761847f8eSopenharmony_ci   */
3861847f8eSopenharmony_ci  function getAudioHapticManager(): AudioHapticManager;
3961847f8eSopenharmony_ci
4061847f8eSopenharmony_ci  /**
4161847f8eSopenharmony_ci   * Audio Latency mode.
4261847f8eSopenharmony_ci   * @enum {number}
4361847f8eSopenharmony_ci   * @syscap SystemCapability.Multimedia.AudioHaptic.Core
4461847f8eSopenharmony_ci   * @since 11
4561847f8eSopenharmony_ci   */
4661847f8eSopenharmony_ci  enum AudioLatencyMode {
4761847f8eSopenharmony_ci    /**
4861847f8eSopenharmony_ci     * Normal audio mode.
4961847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
5061847f8eSopenharmony_ci     * @since 11
5161847f8eSopenharmony_ci     */
5261847f8eSopenharmony_ci    AUDIO_LATENCY_MODE_NORMAL = 0,
5361847f8eSopenharmony_ci
5461847f8eSopenharmony_ci    /**
5561847f8eSopenharmony_ci     * Low latency mode. This mode should be used when duration of the audio source is short. If duration of the audio 
5661847f8eSopenharmony_ci     * source is long, it may be truncated. This behavior is the same with sound pool.
5761847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
5861847f8eSopenharmony_ci     * @since 11
5961847f8eSopenharmony_ci     */
6061847f8eSopenharmony_ci    AUDIO_LATENCY_MODE_FAST = 1
6161847f8eSopenharmony_ci  }
6261847f8eSopenharmony_ci
6361847f8eSopenharmony_ci  /**
6461847f8eSopenharmony_ci   * Audio haptic player options object.
6561847f8eSopenharmony_ci   * @typedef AudioHapticPlayerOptions
6661847f8eSopenharmony_ci   * @syscap SystemCapability.Multimedia.AudioHaptic.Core
6761847f8eSopenharmony_ci   * @since 11
6861847f8eSopenharmony_ci   */
6961847f8eSopenharmony_ci  interface AudioHapticPlayerOptions {
7061847f8eSopenharmony_ci    /**
7161847f8eSopenharmony_ci     * Mute audio.
7261847f8eSopenharmony_ci     * @type {?boolean}
7361847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
7461847f8eSopenharmony_ci     * @since 11
7561847f8eSopenharmony_ci     */
7661847f8eSopenharmony_ci    muteAudio?: boolean;
7761847f8eSopenharmony_ci
7861847f8eSopenharmony_ci    /**
7961847f8eSopenharmony_ci     * Mute haptics.
8061847f8eSopenharmony_ci     * @type {?boolean}
8161847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
8261847f8eSopenharmony_ci     * @since 11
8361847f8eSopenharmony_ci     */
8461847f8eSopenharmony_ci    muteHaptics?: boolean;
8561847f8eSopenharmony_ci  }
8661847f8eSopenharmony_ci
8761847f8eSopenharmony_ci  /**
8861847f8eSopenharmony_ci   * Audio haptic manager object.
8961847f8eSopenharmony_ci   * @typedef AudioHapticManager
9061847f8eSopenharmony_ci   * @syscap SystemCapability.Multimedia.AudioHaptic.Core
9161847f8eSopenharmony_ci   * @since 11
9261847f8eSopenharmony_ci   */
9361847f8eSopenharmony_ci  interface AudioHapticManager {
9461847f8eSopenharmony_ci    /**
9561847f8eSopenharmony_ci     * Register audio and haptic file into manager. Audio and haptic works are paired while playing. After registering
9661847f8eSopenharmony_ci     * source, it will returns the source id. This method uses a promise to return the source id.
9761847f8eSopenharmony_ci     * @param { string } audioUri - Audio file uri.
9861847f8eSopenharmony_ci     * @param { string } hapticUri - Haptic file uri.
9961847f8eSopenharmony_ci     * @returns { Promise<number> } Promise used to return the source id.
10061847f8eSopenharmony_ci     * @throws { BusinessError } 401 - Parameter error. Possible causes:
10161847f8eSopenharmony_ci     *                                 1.Mandatory parameters are left unspecified;
10261847f8eSopenharmony_ci     *                                 2.Incorrect parameter types.
10361847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
10461847f8eSopenharmony_ci     * @since 11
10561847f8eSopenharmony_ci     */
10661847f8eSopenharmony_ci    registerSource(audioUri: string, hapticUri: string): Promise<number>;
10761847f8eSopenharmony_ci
10861847f8eSopenharmony_ci    /**
10961847f8eSopenharmony_ci     * Unregister source. This method uses a promise to return the result.
11061847f8eSopenharmony_ci     * @param { number } id source id.
11161847f8eSopenharmony_ci     * @returns { Promise<void> } Promise used to return the result.
11261847f8eSopenharmony_ci     * @throws { BusinessError } 401 - Parameter error. Possible causes:
11361847f8eSopenharmony_ci     *                                 1.Mandatory parameters are left unspecified;
11461847f8eSopenharmony_ci     *                                 2.Incorrect parameter types.
11561847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
11661847f8eSopenharmony_ci     * @since 11
11761847f8eSopenharmony_ci     */
11861847f8eSopenharmony_ci    unregisterSource(id: number): Promise<void>;
11961847f8eSopenharmony_ci
12061847f8eSopenharmony_ci    /**
12161847f8eSopenharmony_ci     * Set the audio latency mode of one source.
12261847f8eSopenharmony_ci     * @param { number } id - Source id.
12361847f8eSopenharmony_ci     * @param { AudioLatencyMode } latencyMode - Audio latency mode.
12461847f8eSopenharmony_ci     * @throws { BusinessError } 401 - Parameter error. Possible causes:
12561847f8eSopenharmony_ci     *                                 1.Mandatory parameters are left unspecified;
12661847f8eSopenharmony_ci     *                                 2.Incorrect parameter types.
12761847f8eSopenharmony_ci     * @throws { BusinessError } 5400102 - Operation not allowed.
12861847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
12961847f8eSopenharmony_ci     * @since 11
13061847f8eSopenharmony_ci     */
13161847f8eSopenharmony_ci    setAudioLatencyMode(id:number, latencyMode: AudioLatencyMode): void;
13261847f8eSopenharmony_ci
13361847f8eSopenharmony_ci    /**
13461847f8eSopenharmony_ci     * Set the stream usage of one source.
13561847f8eSopenharmony_ci     * @param { number } id - Source id.
13661847f8eSopenharmony_ci     * @param { audio.StreamUsage } usage - Stream usage.
13761847f8eSopenharmony_ci     * @throws { BusinessError } 401 - Parameter error. Possible causes:
13861847f8eSopenharmony_ci     *                                 1.Mandatory parameters are left unspecified;
13961847f8eSopenharmony_ci     *                                 2.Incorrect parameter types;
14061847f8eSopenharmony_ci     *                                 3.Parameter verification failed.
14161847f8eSopenharmony_ci     * @throws { BusinessError } 5400102 - Operation not allowed.
14261847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
14361847f8eSopenharmony_ci     * @since 11
14461847f8eSopenharmony_ci     */
14561847f8eSopenharmony_ci    setStreamUsage(id: number, usage: audio.StreamUsage): void;
14661847f8eSopenharmony_ci
14761847f8eSopenharmony_ci    /**
14861847f8eSopenharmony_ci     * Create an audio haptic player. This method uses a promise to return the result. If haptics is needed, caller
14961847f8eSopenharmony_ci     * should have the permission of ohos.permission.VIBRATE.
15061847f8eSopenharmony_ci     * @permission ohos.permission.VIBRATE
15161847f8eSopenharmony_ci     * @param { number } id - Source id.
15261847f8eSopenharmony_ci     * @param { AudioHapticPlayerOptions } options - Options when creating audio haptic player.
15361847f8eSopenharmony_ci     * @returns { Promise<AudioHapticPlayer> } Promise used to return the result.
15461847f8eSopenharmony_ci     * @throws { BusinessError } 201 - Permission denied.
15561847f8eSopenharmony_ci     * @throws { BusinessError } 401 - Parameter error. Possible causes:
15661847f8eSopenharmony_ci     *                                 1.Mandatory parameters are left unspecified;
15761847f8eSopenharmony_ci     *                                 2.Incorrect parameter types.
15861847f8eSopenharmony_ci     * @throws { BusinessError } 5400102 - Operation not allowed.
15961847f8eSopenharmony_ci     * @throws { BusinessError } 5400103 - I/O error.
16061847f8eSopenharmony_ci     * @throws { BusinessError } 5400106 - Unsupport format.
16161847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
16261847f8eSopenharmony_ci     * @since 11
16361847f8eSopenharmony_ci     */
16461847f8eSopenharmony_ci    createPlayer(id: number, options?: AudioHapticPlayerOptions): Promise<AudioHapticPlayer>;
16561847f8eSopenharmony_ci  }
16661847f8eSopenharmony_ci
16761847f8eSopenharmony_ci  /**
16861847f8eSopenharmony_ci   * Type of audio haptic.
16961847f8eSopenharmony_ci   * @enum {number}
17061847f8eSopenharmony_ci   * @syscap SystemCapability.Multimedia.AudioHaptic.Core
17161847f8eSopenharmony_ci   * @since 11
17261847f8eSopenharmony_ci   */
17361847f8eSopenharmony_ci  enum AudioHapticType {
17461847f8eSopenharmony_ci    /**
17561847f8eSopenharmony_ci     * Audio.
17661847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
17761847f8eSopenharmony_ci     * @since 11
17861847f8eSopenharmony_ci     */
17961847f8eSopenharmony_ci    AUDIO_HAPTIC_TYPE_AUDIO = 0,
18061847f8eSopenharmony_ci
18161847f8eSopenharmony_ci    /**
18261847f8eSopenharmony_ci     * Haptic.
18361847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
18461847f8eSopenharmony_ci     * @since 11
18561847f8eSopenharmony_ci     */
18661847f8eSopenharmony_ci    AUDIO_HAPTIC_TYPE_HAPTIC = 1,
18761847f8eSopenharmony_ci  }
18861847f8eSopenharmony_ci
18961847f8eSopenharmony_ci  /**
19061847f8eSopenharmony_ci   * Audio haptic player object.
19161847f8eSopenharmony_ci   * @typedef AudioHapticPlayer
19261847f8eSopenharmony_ci   * @syscap SystemCapability.Multimedia.AudioHaptic.Core
19361847f8eSopenharmony_ci   * @since 11
19461847f8eSopenharmony_ci   */
19561847f8eSopenharmony_ci  interface AudioHapticPlayer {
19661847f8eSopenharmony_ci    /**
19761847f8eSopenharmony_ci     * Is muted for one AudioHapticType
19861847f8eSopenharmony_ci     * @param { AudioHapticType } type - Indicates the type to query.
19961847f8eSopenharmony_ci     * @returns { boolean } - Is muted.
20061847f8eSopenharmony_ci     * @throws { BusinessError } 401 - Parameter error. Possible causes:
20161847f8eSopenharmony_ci     *                                 1.Mandatory parameters are left unspecified;
20261847f8eSopenharmony_ci     *                                 2.Parameter verification failed.
20361847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
20461847f8eSopenharmony_ci     * @since 11
20561847f8eSopenharmony_ci     */
20661847f8eSopenharmony_ci    isMuted(type: AudioHapticType): boolean;
20761847f8eSopenharmony_ci
20861847f8eSopenharmony_ci    /**
20961847f8eSopenharmony_ci     * Start this player. This method uses a promise to return the result.
21061847f8eSopenharmony_ci     * @returns { Promise<void> } Promise used to return the result.
21161847f8eSopenharmony_ci     * @throws { BusinessError } 5400102 - Operate not permit.
21261847f8eSopenharmony_ci     * @throws { BusinessError } 5400103 - IO error.
21361847f8eSopenharmony_ci     * @throws { BusinessError } 5400105 - Service died.
21461847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
21561847f8eSopenharmony_ci     * @since 11
21661847f8eSopenharmony_ci     */
21761847f8eSopenharmony_ci    start(): Promise<void>;
21861847f8eSopenharmony_ci
21961847f8eSopenharmony_ci    /**
22061847f8eSopenharmony_ci     * Stop this player. This method uses a promise to return the result.
22161847f8eSopenharmony_ci     * @returns { Promise<void> } Promise used to return the result.
22261847f8eSopenharmony_ci     * @throws { BusinessError } 5400102 - Operate not permit.
22361847f8eSopenharmony_ci     * @throws { BusinessError } 5400105 - Service died.
22461847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
22561847f8eSopenharmony_ci     * @since 11
22661847f8eSopenharmony_ci     */
22761847f8eSopenharmony_ci    stop(): Promise<void>;
22861847f8eSopenharmony_ci
22961847f8eSopenharmony_ci    /**
23061847f8eSopenharmony_ci     * Release this player. This method uses a promise to return the result.
23161847f8eSopenharmony_ci     * @returns { Promise<void> } Promise used to return the result.
23261847f8eSopenharmony_ci     * @throws { BusinessError } 5400105 - Service died.
23361847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
23461847f8eSopenharmony_ci     * @since 11
23561847f8eSopenharmony_ci     */
23661847f8eSopenharmony_ci    release(): Promise<void>;
23761847f8eSopenharmony_ci
23861847f8eSopenharmony_ci    /**
23961847f8eSopenharmony_ci     * Subscribes end of stream event.
24061847f8eSopenharmony_ci     * @param { 'endOfStream' } type - Type of the playback event to listen for.
24161847f8eSopenharmony_ci     * @param { Callback<void> } callback - Callback used to listen for the playback end of stream.
24261847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
24361847f8eSopenharmony_ci     * @since 11
24461847f8eSopenharmony_ci     */
24561847f8eSopenharmony_ci    on(type: 'endOfStream', callback: Callback<void>): void;
24661847f8eSopenharmony_ci
24761847f8eSopenharmony_ci    /**
24861847f8eSopenharmony_ci     * Unsubscribes end of stream event.
24961847f8eSopenharmony_ci     * @param { 'endOfStream' } type - Type of the playback event to listen for.
25061847f8eSopenharmony_ci     * @param { Callback<void> } callback - Callback used to listen for the playback end of stream.
25161847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
25261847f8eSopenharmony_ci     * @since 11
25361847f8eSopenharmony_ci     */
25461847f8eSopenharmony_ci    off(type: 'endOfStream', callback?: Callback<void>): void;
25561847f8eSopenharmony_ci
25661847f8eSopenharmony_ci    /**
25761847f8eSopenharmony_ci     * Subscribes audio interrupt event.
25861847f8eSopenharmony_ci     * @param { 'audioInterrupt' } type - Type of the playback event to listen for.
25961847f8eSopenharmony_ci     * @param { Callback<audio.InterruptEvent> } callback - Callback used to listen for audio interrupt info.
26061847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
26161847f8eSopenharmony_ci     * @since 11
26261847f8eSopenharmony_ci     */
26361847f8eSopenharmony_ci    on(type: 'audioInterrupt', callback: Callback<audio.InterruptEvent>): void;
26461847f8eSopenharmony_ci
26561847f8eSopenharmony_ci    /**
26661847f8eSopenharmony_ci     * Unsubscribes audio interrupt event.
26761847f8eSopenharmony_ci     * @param { 'audioInterrupt' } type - Type of the playback event to listen for.
26861847f8eSopenharmony_ci     * @param { Callback<audio.InterruptEvent> } callback - Callback used to listen for audio interrupt info.
26961847f8eSopenharmony_ci     * @syscap SystemCapability.Multimedia.AudioHaptic.Core
27061847f8eSopenharmony_ci     * @since 11
27161847f8eSopenharmony_ci     */
27261847f8eSopenharmony_ci    off(type: 'audioInterrupt', callback?: Callback<audio.InterruptEvent>): void;
27361847f8eSopenharmony_ci  }
27461847f8eSopenharmony_ci}
27561847f8eSopenharmony_ciexport default audioHaptic;
276