1/* 2 * Copyright (c) 2021-2025 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 MediaKit 19 */ 20 21import type { ErrorCallback, AsyncCallback, Callback, BusinessError } from '../@ohos.base'; 22import type audio from '../@ohos.multimedia.audio'; 23import media from '../@ohos.multimedia.media'; 24import resourceManager from '../@ohos.resourceManager'; 25 26/** 27 * Enumerates the error type. 28 * @enum { number } 29 * @syscap SystemCapability.Multimedia.Media.SoundPool 30 * @since 20 31 */ 32export enum ErrorType { 33 /** 34 * Load error. 35 * @syscap SystemCapability.Multimedia.Media.SoundPool 36 * @since 20 37 */ 38 LOAD_ERROR = 1, 39 40 /** 41 * Play error. 42 * @syscap SystemCapability.Multimedia.Media.SoundPool 43 * @since 20 44 */ 45 PLAY_ERROR = 2 46} 47 48/** 49 * Interface for error info. 50 * @typedef { ErrorInfo<T extends Error = BusinessError> } 51 * @syscap SystemCapability.Multimedia.Media.SoundPool 52 * @since 20 53 */ 54export interface ErrorInfo<T extends Error = BusinessError> { 55 /** 56 * Error code. 57 * @type { T } 58 * @syscap SystemCapability.Multimedia.Media.SoundPool 59 * @since 20 60 */ 61 errorCode: T; 62 /** 63 * Error type. 64 * @type { ?ErrorType } 65 * @syscap SystemCapability.Multimedia.Media.SoundPool 66 * @since 20 67 */ 68 errorType?: ErrorType; 69 /** 70 * Sound id, returned from SoundPool.load function. 71 * @type { ?number } 72 * @syscap SystemCapability.Multimedia.Media.SoundPool 73 * @since 20 74 */ 75 soundId?: number; 76 /** 77 * Stream id, returned from SoundPool.play function. 78 * @type { ?number } 79 * @syscap SystemCapability.Multimedia.Media.SoundPool 80 * @since 20 81 */ 82 streamId?: number; 83} 84 85/** 86 * Describes the playback parameters of the sound pool. 87 * 88 * These parameters are used to control the playback volume, number of loops, and priority. 89 * 90 * @typedef PlayParameters 91 * @syscap SystemCapability.Multimedia.Media.SoundPool 92 * @since 10 93 */ 94export interface PlayParameters { 95 /** 96 * Number of loops. 97 * 98 * If this parameter is set to a value greater than or equal to 0, the number of times the content 99 * is actually played is the value of **loop** plus 1. 100 * 101 * If this parameter is set to a value less than 0, the content is played repeatedly. 102 * 103 * The default value is **0**, indicating that the content is played only once. 104 * 105 * @type { ?number } 106 * @syscap SystemCapability.Multimedia.Media.SoundPool 107 * @since 10 108 */ 109 loop?: number; 110 /** 111 * Playback rate. For details, see [AudioRendererRate]{@link #audio.AudioRendererRate}. Default value: **0**. 112 * 113 * @type { ?number } 114 * @syscap SystemCapability.Multimedia.Media.SoundPool 115 * @since 10 116 */ 117 rate?: number; 118 /** 119 * Volume of the left channel. The value ranges from 0.0 to 1.0. Default value: **1.0**. 120 * 121 * @type { ?number } 122 * @syscap SystemCapability.Multimedia.Media.SoundPool 123 * @since 10 124 */ 125 leftVolume?: number; 126 /** 127 * Volume of the right channel. The value ranges from 0.0 to 1.0. (Currently, the volume cannot be set separately 128 * for the left and right channels. The volume set for the left channel is used.) Default value: **1.0**. 129 * 130 * @type { ?number } 131 * @syscap SystemCapability.Multimedia.Media.SoundPool 132 * @since 10 133 */ 134 rightVolume?: number; 135 /** 136 * Playback priority. The value **0** means the lowest priority. A larger value indicates a higher priority. 137 * The value is an integer greater than or equal to 0. Default value: **0**. 138 * 139 * @type { ?number } 140 * @syscap SystemCapability.Multimedia.Media.SoundPool 141 * @since 10 142 */ 143 priority?: number; 144 /** 145 * Whether the sound can be played in parallel with other active audio streams. The value **true** means that the 146 * sound can be played in parallel with other active audio streams, without preempting the audio focus, 147 * and **false** means the opposite. The default value is **false**. 148 * 149 * This is a system API. 150 * 151 * @type { ?boolean } 152 * @syscap SystemCapability.Multimedia.Media.SoundPool 153 * @systemapi 154 * @since 10 155 */ 156 parallelPlayFlag?: boolean; 157} 158 159/** 160 * Implements a sound pool that provides APIs for loading, unloading, playing, and stopping playing system sounds, 161 * setting the volume, and setting the number of loops. Before using these APIs, you must call 162 * [createSoundPool]{@link #media.createSoundPool} to create a **SoundPool** instance. 163 * 164 * **NOTE** 165 * 166 * When using the **SoundPool** instance, you are advised to register the following callbacks to proactively obtain 167 * status changes: 168 * - on('loadComplete'): listens for the event indicating that the resource loading is finished. 169 * - on('playFinishedWithStreamId'): listens for the event indicating that the playback is finished and 170 * returns the stream ID of the audio that finishes playing. 171 * - on('playFinished'): listens for the event indicating that the playback is finished. 172 * - on('error'): listens for error events. 173 * 174 * @typedef SoundPool 175 * @syscap SystemCapability.Multimedia.Media.SoundPool 176 * @since 10 177 */ 178export interface SoundPool { 179 /** 180 * Loads a sound. This API uses an asynchronous callback to obtain the sound ID. 181 * The input parameter **uri** is a string starting with fd://, which is generated based on the file descriptor (FD) 182 * obtained. This API cannot be used to load resources in the **rawfile** directory. 183 * Instead, use load(fd: number, offset: number, length: number, callback: AsyncCallback<number>): void or 184 * load(fd: number, offset: number, length: number): Promise<number>. 185 * 186 * **NOTE** 187 * 188 * After the resource handle (in the form of an FD) or path description (in the form of a URI) is transferred to 189 * the AVPlayer, do not use the resource handle or path description in read or write operations, 190 * including but not limited to transferring it to multiple AVPlayers. Competition occurs when multiple AVPlayers use 191 * the same resource handle or path description to read and write files at the same time, resulting in playback errors. 192 * 193 * @param {string} uri - URI of the audio file to load. Generally, the URI starts with fd://. 194 * @param {AsyncCallback<number>} callback - Callback used to return the sound ID. A valid value must be 195 * greater than 0. 196 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 197 * @throws { BusinessError } 5400103 - I/O error. Return by callback. 198 * @throws { BusinessError } 5400105 - Service died. Return by callback. 199 * @syscap SystemCapability.Multimedia.Media.SoundPool 200 * @since 10 201 */ 202 load(uri: string, callback: AsyncCallback<number>): void; 203 /** 204 * Loads a sound. This API uses a promise to obtain the sound ID. The input parameter **uri** is a starting with 205 * fd://, which is generated based on the FD obtained. This API cannot be used to load resources in the **rawfile** 206 * directory. 207 * Instead, use load(fd: number, offset: number, length: number, callback: AsyncCallback<number>): void or 208 * load(fd: number, offset: number, length: number): Promise<number>. 209 * 210 * **NOTE** 211 * 212 * After the resource handle (in the form of an FD) or path description (in the form of a URI) 213 * is transferred to the AVPlayer, do not use the resource handle or path description in read or write operations, 214 * including but not limited to transferring it to multiple AVPlayers. Competition occurs when multiple AVPlayers 215 * use the same resource handle or path description to read and write files at the same time, 216 * resulting in playback errors. 217 * 218 * @param {string} uri - URI of the audio file to load. Generally, the URI starts with fd://. 219 * @returns {Promise<number>} Promise used to return the sound ID. A valid value must be greater than 0. 220 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 221 * @throws { BusinessError } 5400103 - I/O error. Return by promise. 222 * @throws { BusinessError } 5400105 - Service died. Return by promise. 223 * @syscap SystemCapability.Multimedia.Media.SoundPool 224 * @since 10 225 */ 226 load(uri: string): Promise<number>; 227 /** 228 * Loads a sound. This API uses an asynchronous callback to obtain the sound ID. The input parameter **fd** can be 229 * manually input or automatically obtained by reading the embedded resource of the application. 230 * 231 * **NOTE** 232 * 233 * After the resource handle (in the form of an FD) or path description (in the form of a URI) is transferred to 234 * the AVPlayer, do not use the resource handle or path description in read or write operations, including but not 235 * limited to transferring it to multiple AVPlayers. Competition occurs when multiple AVPlayers use the same resource 236 * handle or path description to read and write files at the same time, resulting in playback errors. 237 * 238 * @param {number} fd - Resource handle, which is obtained by calling 239 * [resourceManager.getRawFd]{@link resourceManager.resourceManager.getRawFile}. 240 * @param {number} offset - Resource offset, which needs to be entered based on the preset resource information. 241 * An invalid value causes a failure to parse audio and video resources. 242 * @param {number} length - Resource length, which needs to be entered based on the preset resource information. 243 * An invalid value causes a failure to parse audio and video resources. 244 * @param {AsyncCallback<number>} callback - Callback used to return the sound ID. 245 * A valid value must be greater than 0. 246 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 247 * @throws { BusinessError } 5400103 - I/O error. Return by callback. 248 * @throws { BusinessError } 5400105 - Service died. Return by callback. 249 * @syscap SystemCapability.Multimedia.Media.SoundPool 250 * @since 10 251 */ 252 load(fd: number, offset: number, length: number, callback: AsyncCallback<number>): void; 253 /** 254 * Loads a sound. This API uses a promise to obtain the sound ID. The input parameter **fd** can be manually input or 255 * automatically obtained by reading the embedded resource of the application. 256 * 257 * **NOTE** 258 * 259 * After the resource handle (in the form of an FD) or path description (in the form of a URI) is transferred to the 260 * AVPlayer, do not use the resource handle or path description in read or write operations, including but not 261 * limited to transferring it to multiple AVPlayers. Competition occurs when multiple AVPlayers use the same resource 262 * handle or path description to read and write files at the same time, resulting in playback errors. 263 * 264 * @param {number} fd - Resource handle, which is obtained by calling 265 * [resourceManager.getRawFd]{@link resourceManager.resourceManager.getRawFile}. 266 * @param {number} offset - Resource offset, which needs to be entered based on the preset resource information. 267 * An invalid value causes a failure to parse audio and video resources. 268 * @param {number} length - Resource length, which needs to be entered based on the preset resource information. 269 * An invalid value causes a failure to parse audio and video resources. 270 * @returns {Promise<number>} Promise used to return the sound ID. A valid value must be greater than 0. 271 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 272 * @throws { BusinessError } 5400103 - I/O error. Return by promise. 273 * @throws { BusinessError } 5400105 - Service died. Return by promise. 274 * @syscap SystemCapability.Multimedia.Media.SoundPool 275 * @since 10 276 */ 277 load(fd: number, offset: number, length: number): Promise<number>; 278 /** 279 * Plays a sound. This API uses an asynchronous callback to obtain the audio stream ID. 280 * 281 * @param {number} soundID - Sound ID, which is obtained by calling **load()**. 282 * @param {PlayParameters} params - Playback parameters. 283 * @param {AsyncCallback<number>} callback - Callback used to return the audio stream ID. 284 * A valid value must be greater than 0. 285 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 286 * 2.Incorrect parameter types. 3.Parameter verification failed. Return by callback. 287 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 288 * @throws { BusinessError } 5400105 - Service died. Return by callback. 289 * @syscap SystemCapability.Multimedia.Media.SoundPool 290 * @since 10 291 */ 292 play(soundID: number, params: PlayParameters, callback: AsyncCallback<number>): void; 293 /** 294 * Plays a sound. This API uses an asynchronous callback to obtain the audio stream ID. 295 * 296 * @param {number} soundID - Sound ID, which is obtained by calling **load()**. 297 * @param {AsyncCallback<number>} callback - Callback used to return the audio stream ID. 298 * A valid value must be greater than 0. 299 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 300 * 2.Incorrect parameter types. 3.Parameter verification failed. Return by callback. 301 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 302 * @throws { BusinessError } 5400105 - Service died. Return by callback. 303 * @syscap SystemCapability.Multimedia.Media.SoundPool 304 * @since 10 305 */ 306 play(soundID: number, callback: AsyncCallback<number>): void; 307 /** 308 * Plays a sound. This API uses a promise to obtain the audio stream ID. 309 * 310 * @param {number} soundID - Sound ID, which is obtained by calling **load()**. 311 * @param {PlayParameters} params - Playback parameters. 312 * @returns {Promise<number>} Promise used to return the audio stream ID. A valid value must be greater than 0. 313 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 314 * 2.Incorrect parameter types. 3.Parameter verification failed. Return by promise. 315 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 316 * @throws { BusinessError } 5400105 - Service died. Return by promise. 317 * @syscap SystemCapability.Multimedia.Media.SoundPool 318 * @since 10 319 */ 320 play(soundID: number, params?: PlayParameters): Promise<number>; 321 /** 322 * Stops playing a sound. This API uses an asynchronous callback to return the result. 323 * 324 * @param {number} streamID - Audio stream ID, which is obtained by calling **play()**. 325 * @param {AsyncCallback<void>} callback - Callback used to return the result. 326 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 327 * 2.Incorrect parameter types. 3.Parameter verification failed. Return by callback. 328 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 329 * @throws { BusinessError } 5400105 - Service died. Return by callback. 330 * @syscap SystemCapability.Multimedia.Media.SoundPool 331 * @since 10 332 */ 333 stop(streamID: number, callback: AsyncCallback<void>): void; 334 /** 335 * Stops playing a sound. This API uses a promise to return the result. 336 * 337 * @param {number} streamID - Audio stream ID, which is obtained by calling **play()**. 338 * @returns {Promise<void>} Promise that returns no value. 339 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 340 * 2.Incorrect parameter types. 3.Parameter verification failed. Return by promise. 341 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 342 * @throws { BusinessError } 5400105 - Service died. Return by promise. 343 * @syscap SystemCapability.Multimedia.Media.SoundPool 344 * @since 10 345 */ 346 stop(streamID: number): Promise<void>; 347 /** 348 * Sets the loop mode for an audio stream. This API uses an asynchronous callback to return the result. 349 * 350 * @param {number} streamID - Audio stream ID, which is obtained by calling **play()**. 351 * @param {number} loop - Number of loops. 352 * 353 * If this parameter is set to a value greater than or equal to 0, the number of times the content is actually 354 * played is the value of **loop** plus 1. 355 * 356 * If this parameter is set to a value less than 0, the content is played repeatedly. 357 * @param {AsyncCallback<void>} callback - Callback used to return the result. 358 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 359 * 2.Incorrect parameter types. 3.Parameter verification failed. Return by callback. 360 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 361 * @throws { BusinessError } 5400105 - Service died. Return by callback. 362 * @syscap SystemCapability.Multimedia.Media.SoundPool 363 * @since 10 364 */ 365 setLoop(streamID: number, loop: number, callback: AsyncCallback<void>): void; 366 /** 367 * Sets the loop mode for an audio stream. This API uses a promise to return the result. 368 * 369 * @param {number} streamID - Audio stream ID, which is obtained by calling **play()**. 370 * @param {number} loop - Number of loops. 371 * 372 * If this parameter is set to a value greater than or equal to 0, the number of times the content is actually 373 * played is the value of **loop** plus 1. 374 * 375 * If this parameter is set to a value less than 0, the content is played repeatedly. 376 * @returns {Promise<void>} Promise that returns no value. 377 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 378 * 2.Incorrect parameter types. 3.Parameter verification failed. Return by promise. 379 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 380 * @throws { BusinessError } 5400105 - Service died. Return by promise. 381 * @syscap SystemCapability.Multimedia.Media.SoundPool 382 * @since 10 383 */ 384 setLoop(streamID: number, loop: number): Promise<void>; 385 /** 386 * Sets the priority for an audio stream. This API uses an asynchronous callback to return the result. 387 * 388 * @param {number} streamID - Audio stream ID, which is obtained by calling **play()**. 389 * @param {number} priority - Priority. The value **0** means the lowest priority. The value is an integer 390 * greater than or equal to 0. 391 * @param {AsyncCallback<void>} callback - Callback used to return the result. 392 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 393 * 2.Incorrect parameter types. 3.Parameter verification failed. Return by callback. 394 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 395 * @throws { BusinessError } 5400105 - Service died. Return by callback. 396 * @syscap SystemCapability.Multimedia.Media.SoundPool 397 * @since 10 398 */ 399 setPriority(streamID: number, priority: number, callback: AsyncCallback<void>): void; 400 /** 401 * Sets the priority for an audio stream. This API uses a promise to return the result. 402 * 403 * @param {number} streamID - Audio stream ID, which is obtained by calling **play()**. 404 * @param {number} priority - Priority. The value **0** means the lowest priority. The value is an integer 405 * greater than or equal to 0. 406 * @returns {Promise<void>} Promise that returns no value. 407 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 408 * 2.Incorrect parameter types. 3.Parameter verification failed. Return by promise. 409 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 410 * @throws { BusinessError } 5400105 - Service died. Return by promise. 411 * @syscap SystemCapability.Multimedia.Media.SoundPool 412 * @since 10 413 */ 414 setPriority(streamID: number, priority: number): Promise<void>; 415 /** 416 * Sets the playback rate for an audio stream. This API uses an asynchronous callback to return the result. 417 * 418 * @param {number} streamID - Audio stream ID, which is obtained by calling **play()**. 419 * @param {audio.AudioRendererRate} rate - Playback rate. 420 * @param {AsyncCallback<void>} callback - Callback used to return the result. 421 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 422 * 2.Incorrect parameter types. 3.Parameter verification failed. Return by callback. 423 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 424 * @throws { BusinessError } 5400105 - Service died. Return by callback. 425 * @syscap SystemCapability.Multimedia.Media.SoundPool 426 * @since 10 427 */ 428 setRate(streamID: number, rate: audio.AudioRendererRate, callback: AsyncCallback<void>): void; 429 /** 430 * Sets the playback rate for an audio stream. This API uses a promise to return the result. 431 * 432 * @param {number} streamID - Audio stream ID, which is obtained by calling **play()**. 433 * @param {audio.AudioRendererRate} rate - Playback rate. 434 * @returns {Promise<void>} Promise that returns no value. 435 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 436 * 2.Incorrect parameter types. 3.Parameter verification failed. Return by promise. 437 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 438 * @throws { BusinessError } 5400105 - Service died. Return by promise. 439 * @syscap SystemCapability.Multimedia.Media.SoundPool 440 * @since 10 441 */ 442 setRate(streamID: number, rate: audio.AudioRendererRate): Promise<void>; 443 /** 444 * Sets the volume for an audio stream. This API uses an asynchronous callback to return the result. 445 * 446 * @param {number} streamID - Audio stream ID, which is obtained by calling **play()**. 447 * @param {number} leftVolume - Volume of the left channel. The value ranges from 0.0 to 1.0. 448 * @param {number} rightVolume - Volume of the right channel. The value ranges from 0.0 to 1.0. Currently, 449 * setting the volume for the right channel does not take effect. The volume set for the left channel is used. 450 * @param {AsyncCallback<void>} callback - Callback used to return the result. 451 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 452 * 2.Incorrect parameter types. 3.Parameter verification failed. Return by callback. 453 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 454 * @throws { BusinessError } 5400105 - Service died. Return by callback. 455 * @syscap SystemCapability.Multimedia.Media.SoundPool 456 * @since 10 457 */ 458 setVolume(streamID: number, leftVolume: number, rightVolume: number, callback: AsyncCallback<void>): void; 459 /** 460 * Sets the volume for an audio stream. This API uses a promise to return the result. 461 * 462 * @param {number} streamID - Audio stream ID, which is obtained by calling **play()**. 463 * @param {number} leftVolume - Volume of the left channel. The value ranges from 0.0 to 1.0. 464 * @param {number} rightVolume - Volume of the right channel. The value ranges from 0.0 to 1.0. Currently, 465 * setting the volume for the right channel does not take effect. The volume set for the left channel is used. 466 * @returns {Promise<void>} Promise that returns no value. 467 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified. 468 * 2.Incorrect parameter types. 3.Parameter verification failed. Return by promise. 469 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 470 * @throws { BusinessError } 5400105 - Service died. Return by promise. 471 * @syscap SystemCapability.Multimedia.Media.SoundPool 472 * @since 10 473 */ 474 setVolume(streamID: number, leftVolume: number, rightVolume: number): Promise<void>; 475 /** 476 * Unloads a sound. This API uses an asynchronous callback to return the result. 477 * 478 * @param {number} soundID - Sound ID, which is obtained by calling **load()**. 479 * @param {AsyncCallback<void>} callback - Callback used to return the result. 480 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 481 * @throws { BusinessError } 5400103 - I/O error. Return by callback. 482 * @throws { BusinessError } 5400105 - Service died. Return by callback. 483 * @syscap SystemCapability.Multimedia.Media.SoundPool 484 * @since 10 485 */ 486 unload(soundID: number, callback: AsyncCallback<void>): void; 487 /** 488 * Unloads a sound. This API uses a promise to return the result. 489 * 490 * @param {number} soundID - Sound ID, which is obtained by calling **load()**. 491 * @returns {Promise<void>} Promise that returns no value. 492 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 493 * @throws { BusinessError } 5400103 - I/O error. Return by promise. 494 * @throws { BusinessError } 5400105 - Service died. Return by promise. 495 * @syscap SystemCapability.Multimedia.Media.SoundPool 496 * @since 10 497 */ 498 unload(soundID: number): Promise<void>; 499 /** 500 * Releases this **SoundPool** instance. This API uses an asynchronous callback to return the result. 501 * 502 * @param {AsyncCallback<void>} callback - Callback used to return the result. 503 * @throws { BusinessError } 5400105 - Service died. Return by callback. 504 * @syscap SystemCapability.Multimedia.Media.SoundPool 505 * @since 10 506 */ 507 release(callback: AsyncCallback<void>): void; 508 /** 509 * Releases this **SoundPool** instance. This API uses a promise to return the result. 510 * 511 * @returns {Promise<void>} Promise that returns no value. 512 * @throws { BusinessError } 5400105 - Service died. Return by promise. 513 * @syscap SystemCapability.Multimedia.Media.SoundPool 514 * @since 10 515 */ 516 release(): Promise<void>; 517 /** 518 * Subscribes to events indicating that a sound finishes loading. 519 * 520 * @param {'loadComplete'} type - Event type, which is **'loadComplete'** in this case. 521 * This event is triggered when a sound is loaded. 522 * @param {Callback<number>} callback - ID of the sound that has been loaded. 523 * @syscap SystemCapability.Multimedia.Media.SoundPool 524 * @since 10 525 */ 526 on(type: 'loadComplete', callback: Callback<number>): void; 527 /** 528 * Unsubscribes from events indicating that a sound finishes loading. 529 * 530 * @param {'loadComplete'} type - Event type. The value is fixed at **'loadComplete'**. 531 * @syscap SystemCapability.Multimedia.Media.SoundPool 532 * @since 10 533 */ 534 off(type: 'loadComplete'): void; 535 /** 536 * Subscribes to events indicating the completion of audio playback and returns the stream ID of the audio 537 * that finishes playing. 538 * 539 * When only on('playFinished') or on('playFinishedWithStreamId') is subscribed to, the registered 540 * callback is triggered when the audio playback is complete. 541 * 542 * When both on('playFinished') and on('playFinishedWithStreamId') are subscribed to, 543 * the 'playFinishedWithStreamId' callback is triggered, but the 'playFinished' callback is not triggered, 544 * when the audio playback is complete. 545 * 546 * @param {'playFinishedWithStreamId'} type - Event type, which is **'playFinishedWithStreamId'** in this case. 547 * This event is triggered when an audio stream finishes playing, and the stream ID is returned. 548 * @param {Callback<number>} callback - Callback used to return the result. Stream ID of the audio that 549 * finishes playing. 550 * @syscap SystemCapability.Multimedia.Media.SoundPool 551 * @since 18 552 */ 553 on(type: 'playFinishedWithStreamId', callback: Callback<number>): void; 554 /** 555 * Unsubscribes from events indicating that a sound finishes playing. 556 * 557 * @param {'playFinishedWithStreamId'} type - Event type. The value is fixed at **'playFinishedWithStreamId'**. 558 * @syscap SystemCapability.Multimedia.Media.SoundPool 559 * @since 18 560 */ 561 off(type: 'playFinishedWithStreamId'): void; 562 /** 563 * Subscribes to events indicating that a sound finishes playing. 564 * 565 * @param {'playFinished'} type - Event type, which is **'playFinished'** in this case. 566 * This event is triggered when a sound finishes playing. 567 * @param {Callback<void>} callback - Callback used to return the result. 568 * @syscap SystemCapability.Multimedia.Media.SoundPool 569 * @since 10 570 */ 571 on(type: 'playFinished', callback: Callback<void>): void; 572 /** 573 * Unsubscribes from events indicating that a sound finishes playing. 574 * 575 * @param {'playFinished'} type - Event type. The value is fixed at **'playFinished'**. 576 * @syscap SystemCapability.Multimedia.Media.SoundPool 577 * @since 10 578 */ 579 off(type: 'playFinished'): void; 580 /** 581 * Subscribes to error events of this **SoundPool** instance. This event is used only for error prompt. 582 * 583 * @param {'error'} type - Event type, which is **'error'** in this case. 584 * This event can be triggered by both user operations and the system. 585 * @param {ErrorCallback} callback - Callback used to return the error code ID and error message. 586 * @syscap SystemCapability.Multimedia.Media.SoundPool 587 * @since 10 588 */ 589 on(type: 'error', callback: ErrorCallback): void; 590 /** 591 * Unsubscribes from error events of this **SoundPool** instance. 592 * 593 * @param {'error'} type - Event type, which is **'error'** in this case. 594 * @syscap SystemCapability.Multimedia.Media.SoundPool 595 * @since 10 596 */ 597 off(type: 'error'): void; 598 /** 599 * Subscribes to errorOccurred events of this **SoundPool** instance. 600 * 601 * @param { 'errorOccurred' } type - Type of the soundpool event to listen for. 602 * @param { Callback<ErrorInfo> } callback - Callback used to listen for soundpool errorOccurred events. 603 * @syscap SystemCapability.Multimedia.Media.SoundPool 604 * @since 20 605 */ 606 on(type: 'errorOccurred', callback: Callback<ErrorInfo>): void; 607 608 /** 609 * Unsubscribes from errorOccurred events of this **SoundPool** instance. 610 * 611 * @param { 'errorOccurred' } type - Type of the soundpool event to listen for. 612 * @param { Callback<ErrorInfo> } [callback] - Callback used to listen for soundpool errorOccurred events. 613 * @syscap SystemCapability.Multimedia.Media.SoundPool 614 * @since 20 615 */ 616 off(type: 'errorOccurred', callback?: Callback<ErrorInfo>): void; 617} 618 619