2023-11-14 02:50:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2023-12-11 09:08:03 +00:00
|
|
|
/**
|
|
|
|
* @file
|
2024-01-08 07:25:39 +00:00
|
|
|
* @kit AudioKit
|
2023-12-11 09:08:03 +00:00
|
|
|
*/
|
|
|
|
|
2023-11-29 00:56:52 +00:00
|
|
|
import type { Callback } from './@ohos.base';
|
2023-11-14 02:50:10 +00:00
|
|
|
import type audio from './@ohos.multimedia.audio';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides audio haptic collaborative play interfaces.
|
|
|
|
*
|
|
|
|
* @namespace audioHaptic
|
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
declare namespace audioHaptic {
|
|
|
|
/**
|
|
|
|
* Obtains an {@link AudioHapticManager} instance. This object is singleton in one process.
|
2023-11-29 00:56:52 +00:00
|
|
|
* @returns { AudioHapticManager } AudioHapticManager instance.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
function getAudioHapticManager(): AudioHapticManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Audio Latency mode.
|
|
|
|
* @enum {number}
|
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
enum AudioLatencyMode {
|
|
|
|
/**
|
|
|
|
* Normal audio mode.
|
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
AUDIO_LATENCY_MODE_NORMAL = 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Low latency mode. This mode should be used when duration of the audio source is short. If duration of the audio
|
|
|
|
* source is long, it may be truncated. This behavior is the same with sound pool.
|
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
AUDIO_LATENCY_MODE_FAST = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Audio haptic player options object.
|
|
|
|
* @typedef AudioHapticPlayerOptions
|
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
interface AudioHapticPlayerOptions {
|
|
|
|
/**
|
|
|
|
* Mute audio.
|
2023-11-29 00:56:52 +00:00
|
|
|
* @type {?boolean}
|
2023-11-14 02:50:10 +00:00
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
muteAudio?: boolean;
|
|
|
|
|
|
|
|
/**
|
2023-11-17 02:33:28 +00:00
|
|
|
* Mute haptics.
|
2023-11-29 00:56:52 +00:00
|
|
|
* @type {?boolean}
|
2023-11-14 02:50:10 +00:00
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
2023-11-17 02:33:28 +00:00
|
|
|
muteHaptics?: boolean;
|
2023-11-14 02:50:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Audio haptic manager object.
|
|
|
|
* @typedef AudioHapticManager
|
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
interface AudioHapticManager {
|
|
|
|
/**
|
|
|
|
* Register audio and haptic file into manager. Audio and haptic works are paired while playing. After registering
|
|
|
|
* source, it will returns the source id. This method uses a promise to return the source id.
|
2023-11-29 00:56:52 +00:00
|
|
|
* @param { string } audioUri - Audio file uri.
|
|
|
|
* @param { string } hapticUri - Haptic file uri.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @returns { Promise<number> } Promise used to return the source id.
|
2024-04-28 09:15:54 +00:00
|
|
|
* @throws { BusinessError } 401 - Parameter error. Possible causes:
|
|
|
|
* 1.Mandatory parameters are left unspecified;
|
|
|
|
* 2.Incorrect parameter types.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
2023-11-29 00:56:52 +00:00
|
|
|
registerSource(audioUri: string, hapticUri: string): Promise<number>;
|
2023-11-14 02:50:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister source. This method uses a promise to return the result.
|
|
|
|
* @param { number } id source id.
|
|
|
|
* @returns { Promise<void> } Promise used to return the result.
|
2024-04-28 09:15:54 +00:00
|
|
|
* @throws { BusinessError } 401 - Parameter error. Possible causes:
|
|
|
|
* 1.Mandatory parameters are left unspecified;
|
|
|
|
* 2.Incorrect parameter types.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
unregisterSource(id: number): Promise<void>;
|
|
|
|
|
|
|
|
/**
|
2023-11-29 00:56:52 +00:00
|
|
|
* Set the audio latency mode of one source.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @param { number } id - Source id.
|
|
|
|
* @param { AudioLatencyMode } latencyMode - Audio latency mode.
|
2024-04-28 09:15:54 +00:00
|
|
|
* @throws { BusinessError } 401 - Parameter error. Possible causes:
|
|
|
|
* 1.Mandatory parameters are left unspecified;
|
|
|
|
* 2.Incorrect parameter types.
|
2023-11-29 00:56:52 +00:00
|
|
|
* @throws { BusinessError } 5400102 - Operation not allowed.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
2023-11-29 00:56:52 +00:00
|
|
|
setAudioLatencyMode(id:number, latencyMode: AudioLatencyMode): void;
|
2023-11-14 02:50:10 +00:00
|
|
|
|
|
|
|
/**
|
2023-11-29 00:56:52 +00:00
|
|
|
* Set the stream usage of one source.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @param { number } id - Source id.
|
2023-11-29 00:56:52 +00:00
|
|
|
* @param { audio.StreamUsage } usage - Stream usage.
|
2024-04-28 09:15:54 +00:00
|
|
|
* @throws { BusinessError } 401 - Parameter error. Possible causes:
|
|
|
|
* 1.Mandatory parameters are left unspecified;
|
|
|
|
* 2.Incorrect parameter types;
|
|
|
|
* 3.Parameter verification failed.
|
2023-11-29 00:56:52 +00:00
|
|
|
* @throws { BusinessError } 5400102 - Operation not allowed.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
2023-11-29 00:56:52 +00:00
|
|
|
setStreamUsage(id: number, usage: audio.StreamUsage): void;
|
2023-11-14 02:50:10 +00:00
|
|
|
|
|
|
|
/**
|
2023-12-19 07:06:51 +00:00
|
|
|
* Create an audio haptic player. This method uses a promise to return the result. If haptics is needed, caller
|
|
|
|
* should have the permission of ohos.permission.VIBRATE.
|
|
|
|
* @permission ohos.permission.VIBRATE
|
2023-11-14 02:50:10 +00:00
|
|
|
* @param { number } id - Source id.
|
|
|
|
* @param { AudioHapticPlayerOptions } options - Options when creating audio haptic player.
|
|
|
|
* @returns { Promise<AudioHapticPlayer> } Promise used to return the result.
|
2023-12-19 07:06:51 +00:00
|
|
|
* @throws { BusinessError } 201 - Permission denied.
|
2024-04-28 09:15:54 +00:00
|
|
|
* @throws { BusinessError } 401 - Parameter error. Possible causes:
|
|
|
|
* 1.Mandatory parameters are left unspecified;
|
|
|
|
* 2.Incorrect parameter types.
|
2023-11-29 00:56:52 +00:00
|
|
|
* @throws { BusinessError } 5400102 - Operation not allowed.
|
|
|
|
* @throws { BusinessError } 5400103 - I/O error.
|
|
|
|
* @throws { BusinessError } 5400106 - Unsupport format.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
2023-11-17 02:33:28 +00:00
|
|
|
createPlayer(id: number, options?: AudioHapticPlayerOptions): Promise<AudioHapticPlayer>;
|
2023-11-14 02:50:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Type of audio haptic.
|
|
|
|
* @enum {number}
|
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
enum AudioHapticType {
|
|
|
|
/**
|
|
|
|
* Audio.
|
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
AUDIO_HAPTIC_TYPE_AUDIO = 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Haptic.
|
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
AUDIO_HAPTIC_TYPE_HAPTIC = 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Audio haptic player object.
|
|
|
|
* @typedef AudioHapticPlayer
|
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
interface AudioHapticPlayer {
|
|
|
|
/**
|
|
|
|
* Is muted for one AudioHapticType
|
|
|
|
* @param { AudioHapticType } type - Indicates the type to query.
|
|
|
|
* @returns { boolean } - Is muted.
|
2024-04-28 09:15:54 +00:00
|
|
|
* @throws { BusinessError } 401 - Parameter error. Possible causes:
|
|
|
|
* 1.Mandatory parameters are left unspecified;
|
|
|
|
* 2.Parameter verification failed.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
isMuted(type: AudioHapticType): boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start this player. This method uses a promise to return the result.
|
|
|
|
* @returns { Promise<void> } Promise used to return the result.
|
2023-11-17 02:33:28 +00:00
|
|
|
* @throws { BusinessError } 5400102 - Operate not permit.
|
|
|
|
* @throws { BusinessError } 5400103 - IO error.
|
|
|
|
* @throws { BusinessError } 5400105 - Service died.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
start(): Promise<void>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop this player. This method uses a promise to return the result.
|
|
|
|
* @returns { Promise<void> } Promise used to return the result.
|
2023-11-17 02:33:28 +00:00
|
|
|
* @throws { BusinessError } 5400102 - Operate not permit.
|
|
|
|
* @throws { BusinessError } 5400105 - Service died.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
stop(): Promise<void>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release this player. This method uses a promise to return the result.
|
|
|
|
* @returns { Promise<void> } Promise used to return the result.
|
2023-11-17 02:33:28 +00:00
|
|
|
* @throws { BusinessError } 5400105 - Service died.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
|
|
|
release(): Promise<void>;
|
|
|
|
|
|
|
|
/**
|
2023-11-29 00:56:52 +00:00
|
|
|
* Subscribes end of stream event.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @param { 'endOfStream' } type - Type of the playback event to listen for.
|
2023-11-29 00:56:52 +00:00
|
|
|
* @param { Callback<void> } callback - Callback used to listen for the playback end of stream.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
2023-11-29 00:56:52 +00:00
|
|
|
on(type: 'endOfStream', callback: Callback<void>): void;
|
2023-11-14 02:50:10 +00:00
|
|
|
|
|
|
|
/**
|
2023-11-29 00:56:52 +00:00
|
|
|
* Unsubscribes end of stream event.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @param { 'endOfStream' } type - Type of the playback event to listen for.
|
2023-12-25 07:01:31 +00:00
|
|
|
* @param { Callback<void> } callback - Callback used to listen for the playback end of stream.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
2023-12-25 07:01:31 +00:00
|
|
|
off(type: 'endOfStream', callback?: Callback<void>): void;
|
2023-11-14 02:50:10 +00:00
|
|
|
|
|
|
|
/**
|
2023-11-29 00:56:52 +00:00
|
|
|
* Subscribes audio interrupt event.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @param { 'audioInterrupt' } type - Type of the playback event to listen for.
|
2023-11-29 00:56:52 +00:00
|
|
|
* @param { Callback<audio.InterruptEvent> } callback - Callback used to listen for audio interrupt info.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
2023-11-29 00:56:52 +00:00
|
|
|
on(type: 'audioInterrupt', callback: Callback<audio.InterruptEvent>): void;
|
2023-11-14 02:50:10 +00:00
|
|
|
|
|
|
|
/**
|
2023-11-29 00:56:52 +00:00
|
|
|
* Unsubscribes audio interrupt event.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @param { 'audioInterrupt' } type - Type of the playback event to listen for.
|
2023-12-25 07:01:31 +00:00
|
|
|
* @param { Callback<audio.InterruptEvent> } callback - Callback used to listen for audio interrupt info.
|
2023-11-14 02:50:10 +00:00
|
|
|
* @syscap SystemCapability.Multimedia.AudioHaptic.Core
|
|
|
|
* @since 11
|
|
|
|
*/
|
2023-12-25 07:01:31 +00:00
|
|
|
off(type: 'audioInterrupt', callback?: Callback<audio.InterruptEvent>): void;
|
2023-11-14 02:50:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
export default audioHaptic;
|