1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit AudioKit 19 */ 20 21import type { Callback } from './@ohos.base'; 22import type audio from './@ohos.multimedia.audio'; 23 24/** 25 * Provides audio haptic collaborative play interfaces. 26 * 27 * @namespace audioHaptic 28 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 29 * @since 11 30 */ 31declare namespace audioHaptic { 32 /** 33 * Obtains an {@link AudioHapticManager} instance. This object is singleton in one process. 34 * @returns { AudioHapticManager } AudioHapticManager instance. 35 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 36 * @since 11 37 */ 38 function getAudioHapticManager(): AudioHapticManager; 39 40 /** 41 * Audio Latency mode. 42 * @enum {number} 43 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 44 * @since 11 45 */ 46 enum AudioLatencyMode { 47 /** 48 * Normal audio mode. 49 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 50 * @since 11 51 */ 52 AUDIO_LATENCY_MODE_NORMAL = 0, 53 54 /** 55 * Low latency mode. This mode should be used when duration of the audio source is short. If duration of the audio 56 * source is long, it may be truncated. This behavior is the same with sound pool. 57 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 58 * @since 11 59 */ 60 AUDIO_LATENCY_MODE_FAST = 1 61 } 62 63 /** 64 * Audio haptic player options object. 65 * @typedef AudioHapticPlayerOptions 66 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 67 * @since 11 68 */ 69 interface AudioHapticPlayerOptions { 70 /** 71 * Mute audio. 72 * @type {?boolean} 73 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 74 * @since 11 75 */ 76 muteAudio?: boolean; 77 78 /** 79 * Mute haptics. 80 * @type {?boolean} 81 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 82 * @since 11 83 */ 84 muteHaptics?: boolean; 85 } 86 87 /** 88 * Audio haptic manager object. 89 * @typedef AudioHapticManager 90 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 91 * @since 11 92 */ 93 interface AudioHapticManager { 94 /** 95 * Register audio and haptic file into manager. Audio and haptic works are paired while playing. After registering 96 * source, it will returns the source id. This method uses a promise to return the source id. 97 * @param { string } audioUri - Audio file uri. 98 * @param { string } hapticUri - Haptic file uri. 99 * @returns { Promise<number> } Promise used to return the source id. 100 * @throws { BusinessError } 401 - Parameter error. Possible causes: 101 * 1.Mandatory parameters are left unspecified; 102 * 2.Incorrect parameter types. 103 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 104 * @since 11 105 */ 106 registerSource(audioUri: string, hapticUri: string): Promise<number>; 107 108 /** 109 * Unregister source. This method uses a promise to return the result. 110 * @param { number } id source id. 111 * @returns { Promise<void> } Promise used to return the result. 112 * @throws { BusinessError } 401 - Parameter error. Possible causes: 113 * 1.Mandatory parameters are left unspecified; 114 * 2.Incorrect parameter types. 115 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 116 * @since 11 117 */ 118 unregisterSource(id: number): Promise<void>; 119 120 /** 121 * Set the audio latency mode of one source. 122 * @param { number } id - Source id. 123 * @param { AudioLatencyMode } latencyMode - Audio latency mode. 124 * @throws { BusinessError } 401 - Parameter error. Possible causes: 125 * 1.Mandatory parameters are left unspecified; 126 * 2.Incorrect parameter types. 127 * @throws { BusinessError } 5400102 - Operation not allowed. 128 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 129 * @since 11 130 */ 131 setAudioLatencyMode(id:number, latencyMode: AudioLatencyMode): void; 132 133 /** 134 * Set the stream usage of one source. 135 * @param { number } id - Source id. 136 * @param { audio.StreamUsage } usage - Stream usage. 137 * @throws { BusinessError } 401 - Parameter error. Possible causes: 138 * 1.Mandatory parameters are left unspecified; 139 * 2.Incorrect parameter types; 140 * 3.Parameter verification failed. 141 * @throws { BusinessError } 5400102 - Operation not allowed. 142 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 143 * @since 11 144 */ 145 setStreamUsage(id: number, usage: audio.StreamUsage): void; 146 147 /** 148 * Create an audio haptic player. This method uses a promise to return the result. If haptics is needed, caller 149 * should have the permission of ohos.permission.VIBRATE. 150 * @permission ohos.permission.VIBRATE 151 * @param { number } id - Source id. 152 * @param { AudioHapticPlayerOptions } options - Options when creating audio haptic player. 153 * @returns { Promise<AudioHapticPlayer> } Promise used to return the result. 154 * @throws { BusinessError } 201 - Permission denied. 155 * @throws { BusinessError } 401 - Parameter error. Possible causes: 156 * 1.Mandatory parameters are left unspecified; 157 * 2.Incorrect parameter types. 158 * @throws { BusinessError } 5400102 - Operation not allowed. 159 * @throws { BusinessError } 5400103 - I/O error. 160 * @throws { BusinessError } 5400106 - Unsupport format. 161 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 162 * @since 11 163 */ 164 createPlayer(id: number, options?: AudioHapticPlayerOptions): Promise<AudioHapticPlayer>; 165 } 166 167 /** 168 * Type of audio haptic. 169 * @enum {number} 170 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 171 * @since 11 172 */ 173 enum AudioHapticType { 174 /** 175 * Audio. 176 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 177 * @since 11 178 */ 179 AUDIO_HAPTIC_TYPE_AUDIO = 0, 180 181 /** 182 * Haptic. 183 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 184 * @since 11 185 */ 186 AUDIO_HAPTIC_TYPE_HAPTIC = 1, 187 } 188 189 /** 190 * Audio haptic player object. 191 * @typedef AudioHapticPlayer 192 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 193 * @since 11 194 */ 195 interface AudioHapticPlayer { 196 /** 197 * Is muted for one AudioHapticType 198 * @param { AudioHapticType } type - Indicates the type to query. 199 * @returns { boolean } - Is muted. 200 * @throws { BusinessError } 401 - Parameter error. Possible causes: 201 * 1.Mandatory parameters are left unspecified; 202 * 2.Parameter verification failed. 203 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 204 * @since 11 205 */ 206 isMuted(type: AudioHapticType): boolean; 207 208 /** 209 * Start this player. This method uses a promise to return the result. 210 * @returns { Promise<void> } Promise used to return the result. 211 * @throws { BusinessError } 5400102 - Operate not permit. 212 * @throws { BusinessError } 5400103 - IO error. 213 * @throws { BusinessError } 5400105 - Service died. 214 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 215 * @since 11 216 */ 217 start(): Promise<void>; 218 219 /** 220 * Stop this player. This method uses a promise to return the result. 221 * @returns { Promise<void> } Promise used to return the result. 222 * @throws { BusinessError } 5400102 - Operate not permit. 223 * @throws { BusinessError } 5400105 - Service died. 224 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 225 * @since 11 226 */ 227 stop(): Promise<void>; 228 229 /** 230 * Release this player. This method uses a promise to return the result. 231 * @returns { Promise<void> } Promise used to return the result. 232 * @throws { BusinessError } 5400105 - Service died. 233 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 234 * @since 11 235 */ 236 release(): Promise<void>; 237 238 /** 239 * Subscribes end of stream event. 240 * @param { 'endOfStream' } type - Type of the playback event to listen for. 241 * @param { Callback<void> } callback - Callback used to listen for the playback end of stream. 242 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 243 * @since 11 244 */ 245 on(type: 'endOfStream', callback: Callback<void>): void; 246 247 /** 248 * Unsubscribes end of stream event. 249 * @param { 'endOfStream' } type - Type of the playback event to listen for. 250 * @param { Callback<void> } callback - Callback used to listen for the playback end of stream. 251 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 252 * @since 11 253 */ 254 off(type: 'endOfStream', callback?: Callback<void>): void; 255 256 /** 257 * Subscribes audio interrupt event. 258 * @param { 'audioInterrupt' } type - Type of the playback event to listen for. 259 * @param { Callback<audio.InterruptEvent> } callback - Callback used to listen for audio interrupt info. 260 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 261 * @since 11 262 */ 263 on(type: 'audioInterrupt', callback: Callback<audio.InterruptEvent>): void; 264 265 /** 266 * Unsubscribes audio interrupt event. 267 * @param { 'audioInterrupt' } type - Type of the playback event to listen for. 268 * @param { Callback<audio.InterruptEvent> } callback - Callback used to listen for audio interrupt info. 269 * @syscap SystemCapability.Multimedia.AudioHaptic.Core 270 * @since 11 271 */ 272 off(type: 'audioInterrupt', callback?: Callback<audio.InterruptEvent>): void; 273 } 274} 275export default audioHaptic; 276