# AudioMusic | oops-framework
Documentation for oops-framework

# Class AudioMusic

背景音乐

#### Hierarchy

- AudioSource
  - AudioMusic

- Defined in assets/core/common/audio/AudioMusic.ts:13

#####
Index

### Constructors

constructor

### Properties

__editorExtras__
__prefab
_clip
_enabled
_id
_isPlay
_loop
_name
_objFlags
_playOnAwake
_player
_progress
_sceneGetter
_url
_volume
node
onComplete
AudioState
EventHandler
EventType
system

### Accessors

__scriptAsset
_isOnLoadCalled
clip
currentTime
duration
enabled
enabledInHierarchy
hideFlags
isValid
loop
name
playOnAwake
playing
progress
state
uuid
volume
maxAudioChannel

### Methods

__preload?
_destroyImmediate
_destruct
_getLocalBounds?
_getRenderScene
_instantiate
_onPreDestroy
_syncStates
addComponent
destroy
getComponent
getComponentInChildren
getComponents
getComponentsInChildren
getPCMData
getSampleRate
lateUpdate?
load
onDestroy
onDisable
onEnable
onFocusInEditor?
onLoad
onLostFocusInEditor?
onRestore?
pause
play
playOneShot
playPrepare
release
resetInEditor?
schedule
scheduleOnce
start?
stop
unschedule
unscheduleAllCallbacks
update
_deferredDestroy

## Constructors

### constructor

- new AudioMusic(name?: string): AudioMusic

- #### Parameters

  - ##### `Optional` name: string

  #### Returns AudioMusic

  Inherited from AudioSource.constructor

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20883

## Properties

### `Internal` __editorExtras__

__editorExtras__: unknown

Inherited from AudioSource.__editorExtras__

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20877

### `Internal` __prefab

__prefab: null | CompPrefabInfo

Inherited from AudioSource.__prefab

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25393

### `Protected` _clip

_clip: null | AudioClip

Inherited from AudioSource._clip

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7464

### _enabled

_enabled: boolean

### Deprecated

since v3.5.0, this is an engine private interface that will be removed in the future.

Inherited from AudioSource._enabled

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25389

### _id

_id: string

For internal usage.

### Deprecated

since v3.5.0, this is an engine private interface that will be removed in the future.

Inherited from AudioSource._id

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25402

### `Private` _isPlay

_isPlay: boolean = false

- Defined in assets/core/common/audio/AudioMusic.ts:19

### `Protected` _loop

_loop: boolean

Inherited from AudioSource._loop

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7466

### `Protected` _name

_name: string

Inherited from AudioSource._name

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20882

### `Internal` _objFlags

_objFlags: number

Inherited from AudioSource._objFlags

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20881

### `Protected` _playOnAwake

_playOnAwake: boolean

Inherited from AudioSource._playOnAwake

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7467

### `Protected` _player

_player: null | _pal_audio__AudioPlayer

Inherited from AudioSource._player

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7465

### `Private` _progress

_progress: number = 0

- Defined in assets/core/common/audio/AudioMusic.ts:17

### `Internal` _sceneGetter

_sceneGetter: null | (() => RenderScene)

Inherited from AudioSource._sceneGetter

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25397

### `Private` _url

_url: string = ...

- Defined in assets/core/common/audio/AudioMusic.ts:18

### `Protected` _volume

_volume: number

Inherited from AudioSource._volume

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7468

### node

node: Node

### En

The node this component is attached to. A component is always attached to a node.

### Zh

该组件被附加到的节点。组件总会附加到一个节点。

### Example

    import { log } from 'cc';
    log(comp.node);

Inherited from AudioSource.node

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25385

### onComplete

onComplete: null | Function = null

背景音乐播放完成回调

- Defined in assets/core/common/audio/AudioMusic.ts:15

### `Static` AudioState

AudioState: typeof _pal_audio_type__AudioState

Inherited from AudioSource.AudioState

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7462

### `Static` EventHandler

EventHandler: typeof EventHandler

Inherited from AudioSource.EventHandler

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25320

### `Static` EventType

EventType: typeof _cocos_audio_audio_source__AudioSourceEventType

Inherited from AudioSource.EventType

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7463

### `Static` system

system: null

Inherited from AudioSource.system

- Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25375

## Accessors

### __scriptAsset

- get __scriptAsset(): null

- ### Deprecated

  since v3.5.0, this is an engine private interface that will be removed in the future.

  #### Returns null

  Inherited from AudioSource.__scriptAsset

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25337

### _isOnLoadCalled

- get _isOnLoadCalled(): number

- ### En

  Returns a value which used to indicate the onLoad get called or not.

  ### Zh

  返回一个值用来判断 onLoad 是否被调用过，不等于 0 时调用过，等于 0 时未调用。

  ### Read Only

  ### Example

      import { log } from 'cc';
      log(this._isOnLoadCalled > 0);

  ### Deprecated

  since v3.5.0, this is an engine private interface that will be removed in the future.

  #### Returns number

  Inherited from AudioSource._isOnLoadCalled

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25374

### clip

- get clip(): null | AudioClip

- #### Returns null | AudioClip

  Inherited from AudioSource.clip

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7476
- set clip(val: null | AudioClip): void

- ### En

  The default AudioClip to be played for this audio source.

  ### Zh

  设定要播放的音频。

  #### Parameters

  - ##### val: null | AudioClip

  #### Returns void

  Inherited from AudioSource.clip

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7475

### currentTime

- get currentTime(): number

- ### En

  Get the current playback time, in seconds.

  ### Zh

  以秒为单位获取当前播放时间。

  #### Returns number

  Inherited from AudioSource.currentTime

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7607
- set currentTime(num: number): void

- ### En

  Set current playback time, in seconds.

  ### Zh

  以秒为单位设置当前播放时间。

  #### Parameters

  - ##### num: number

    playback time to jump to.

  #### Returns void

  Inherited from AudioSource.currentTime

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7600

### duration

- get duration(): number

- ### En

  Get the audio duration, in seconds.

  ### Zh

  获取以秒为单位的音频总时长。

  #### Returns number

  Inherited from AudioSource.duration

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7614

### enabled

- get enabled(): boolean

- ### En

  Indicates whether this component is enabled or not.

  ### Zh

  表示该组件自身是否启用。

  ### Default

  true

  ### Example

      import { log } from 'cc';
      comp.enabled = true;
      log(comp.enabled);

  #### Returns boolean

  Inherited from AudioSource.enabled

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25349
- set enabled(value: boolean): void

- #### Parameters

  - ##### value: boolean

  #### Returns void

  Inherited from AudioSource.enabled

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25350

### enabledInHierarchy

- get enabledInHierarchy(): boolean

- ### En

  Indicates whether this component is enabled and its node is also active in the hierarchy.

  ### Zh

  表示该组件是否被启用并且所在的节点也处于激活状态。

  ### Read Only

  ### Example

      import { log } from 'cc';
      log(comp.enabledInHierarchy);

  #### Returns boolean

  Inherited from AudioSource.enabledInHierarchy

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25361

### hideFlags

- get hideFlags(): Flags

- #### Returns Flags

  Inherited from AudioSource.hideFlags

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20900
- set hideFlags(hideFlags: Flags): void

- ### En

  After inheriting CCObject objects, control whether you need to hide, lock, serialize, and other functions.

  ### Zh

  在继承 CCObject 对象后，控制是否需要隐藏，锁定，序列化等功能。

  #### Parameters

  - ##### hideFlags: Flags

  #### Returns void

  Inherited from AudioSource.hideFlags

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20899

### isValid

- get isValid(): boolean

- ### En

  Indicates whether the object is not yet destroyed. (It will not be available after being destroyed)
  When an object's `destroy` is called, it is actually destroyed after the end of this frame. So `isValid` will return false from the next frame, while `isValid` in the current frame will still be true. If you want to determine whether the current frame has called `destroy`, use `isValid(obj, true)`, but this is often caused by a particular logical requirements, which is not normally required.

  ### Zh

  表示该对象是否可用（被 destroy 后将不可用）。
  当一个对象的 `destroy` 调用以后，会在这一帧结束后才真正销毁。
  因此从下一帧开始 `isValid` 就会返回 false，而当前帧内 `isValid` 仍然会是 true。
  如果希望判断当前帧是否调用过 `destroy`，请使用 `isValid(obj, true)`，不过这往往是特殊的业务需求引起的，通常情况下不需要这样。

  ### Default

  true

  ### Read Only

  ### Example

      import { Node, log } from 'cc';
      const node = new Node();
      log(node.isValid);    // true
      node.destroy();
      log(node.isValid);    // true, still valid in this frame
      // after a frame...
      log(node.isValid);    // false, destroyed in the end of last frame

  #### Returns boolean

  Inherited from AudioSource.isValid

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20927

### loop

- get loop(): boolean

- #### Returns boolean

  Inherited from AudioSource.loop

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7484
- set loop(val: boolean): void

- ### En

  Is looping enabled for this audio source?

  ### Zh

  是否循环播放音频？

  #### Parameters

  - ##### val: boolean

  #### Returns void

  Inherited from AudioSource.loop

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7483

### name

- get name(): string

- #### Returns string

  Inherited from AudioSource.name

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25321
- set name(value: string): void

- #### Parameters

  - ##### value: string

  #### Returns void

  Inherited from AudioSource.name

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25322

### playOnAwake

- get playOnAwake(): boolean

- #### Returns boolean

  Inherited from AudioSource.playOnAwake

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7497
- set playOnAwake(val: boolean): void

- ### En

  Is the autoplay enabled?
  Note that for most platform autoplay will only start
  after a user gesture is received, according to the latest autoplay policy:
  https://www.chromium.org/audio-video/autoplay

  ### Zh

  是否启用自动播放。
  请注意，根据最新的自动播放策略，现在对大多数平台，自动播放只会在第一次收到用户输入后生效。
  参考：https://www.chromium.org/audio-video/autoplay

  #### Parameters

  - ##### val: boolean

  #### Returns void

  Inherited from AudioSource.playOnAwake

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7496

### playing

- get playing(): boolean

- ### En

  Is the audio currently playing?

  ### Zh

  当前音频是否正在播放？

  #### Returns boolean

  Inherited from AudioSource.playing

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7628

### progress

- get progress(): number

- 获取音乐播放进度

  #### Returns number

  - Defined in assets/core/common/audio/AudioMusic.ts:22
- set progress(value: number): void

- 设置音乐当前播放进度

  #### Parameters

  - ##### value: number

    进度百分比0到1之间

  #### Returns void

  - Defined in assets/core/common/audio/AudioMusic.ts:31

### state

- get state(): _pal_audio_type__AudioState

- ### En

  Get current audio state.

  ### Zh

  获取当前音频状态。

  #### Returns _pal_audio_type__AudioState

  Inherited from AudioSource.state

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7621

### uuid

- get uuid(): string

- ### En

  The uuid for editor.

  ### Zh

  组件的 uuid，用于编辑器。

  ### Read Only

  ### Example

      import { log } from 'cc';
      log(comp.uuid);

  #### Returns string

  Inherited from AudioSource.uuid

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25333

### volume

- get volume(): number

- #### Returns number

  Inherited from AudioSource.volume

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7507
- set volume(val: number): void

- ### En

  The volume of this audio source (0.0 to 1.0).
  Note: Volume control may be ineffective on some platforms.

  ### Zh

  音频的音量（大小范围为 0.0 到 1.0）。
  请注意，在某些平台上，音量控制可能不起效。

  #### Parameters

  - ##### val: number

  #### Returns void

  Inherited from AudioSource.volume

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7506

### `Static` maxAudioChannel

- get maxAudioChannel(): number

- #### Returns number

  Inherited from AudioSource.maxAudioChannel

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7461

## Methods

### `Optional` `Private` __preload

- __preload(): void
- `Private`

  ### En

  `__preload` is called before every onLoad.
  It is used to initialize the builtin components internally,
  to avoid checking whether onLoad is called before every public method calls.
  This method should be removed if script priority is supported.

  ### Zh

  `__preload` 在每次onLoad之前调用。
  它用于在内部初始化内置组件，
  以避免在每次公有方法调用之前检查是否调用了onLoad。
  如果支持脚本优先级，则应删除此方法。

  #### Returns void

  Inherited from AudioSource.__preload

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25611

### _destroyImmediate

- _destroyImmediate(): void

- ### Deprecated

  since v3.5.0, this is an engine private interface that will be removed in the future.

  #### Returns void

  Inherited from AudioSource._destroyImmediate

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20978

### _destruct

- _destruct(): void

- ### En

  Clear all references in the instance.

  NOTE: this method will not clear the getter or setter functions which defined in the instance of CCObject.

  ### Zh

  清理实例的所有引用 注意：此方法不会清理实例上的 getter 与 setter 方法。

  ### Deprecated

  since v3.5.0, this is an engine private interface that will be removed in the future.

  ### Example

      // You can override the _destruct method if you need, for example:
            _destruct: function () {
                for (var key in this) {
                    if (this.hasOwnProperty(key)) {
                        switch (typeof this[key]) {
                            case 'string':
                                this[key] = '';
                                break;
                            case 'object':
                            case 'function':
                                this[key] = null;
                                break;
                    }
                }
            }

  #### Returns void

  Inherited from AudioSource._destruct

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20974

### `Optional` `Private` _getLocalBounds

- _getLocalBounds(out_rect: Rect): void
- `Private`

  ### En

  If the component's bounding box is different from the node's, you can implement this method to supply a custom axis aligned bounding box (AABB), so the editor's scene view can perform hit test properly.

  ### Zh

  如果组件的包围盒与节点不同，您可以实现该方法以提供自定义的轴向对齐的包围盒（AABB）， 以便编辑器的场景视图可以正确地执行点选测试。

  #### Parameters

  - ##### out_rect: Rect

    The rect to store the result bounding rect

  #### Returns void

  Inherited from AudioSource._getLocalBounds

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25676

### _getRenderScene

- _getRenderScene(): RenderScene

- ### Deprecated

  since v3.5.0, this is an engine private interface that will be removed in the future.

  #### Returns RenderScene

  Inherited from AudioSource._getRenderScene

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25406

### _instantiate

- _instantiate(cloned?: Component): undefined | Component

- ### Deprecated

  since v3.5.0, this is an engine private interface that will be removed in the future.

  #### Parameters

  - ##### `Optional` cloned: Component

  #### Returns undefined | Component

  Inherited from AudioSource._instantiate

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25530

### _onPreDestroy

- _onPreDestroy(): void

- ### Deprecated

  since v3.5.0, this is an engine private interface that will be removed in the future.

  #### Returns void

  Inherited from AudioSource._onPreDestroy

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25526

### `Protected` _syncStates

- _syncStates(): void

- #### Returns void

  Inherited from AudioSource._syncStates

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7592

### addComponent

- addComponent<T>(classConstructor: __types_globals__Constructor<T>): null | T

- ### En

  Adds a component class to the node. You can also add component to node by passing in the name of the script.

  ### Zh

  向节点添加一个指定类型的组件类，你还可以通过传入脚本的名称来添加组件。

  ### Example

      import { Sprite } from 'cc';
      const sprite = node.addComponent(Sprite);

  #### Type Parameters

  - #### T extends Component<T>

  #### Parameters

  - ##### classConstructor: __types_globals__Constructor<T>

    The class of component to be retrieved or to be created

  #### Returns null | T

  Inherited from AudioSource.addComponent

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25417
- addComponent(className: string): null | Component

- ### En

  Adds a component class to the node. You can also add component to node by passing in the name of the script.

  ### Zh

  向节点添加一个指定类型的组件类，你还可以通过传入脚本的名称来添加组件。

  ### Example

      const test = node.addComponent("Test");

  #### Parameters

  - ##### className: string

    A string for the class name of the component

  #### Returns null | Component

  Inherited from AudioSource.addComponent

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25427

### destroy

- destroy(): boolean

- #### Returns boolean

  Inherited from AudioSource.destroy

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25522

### getComponent

- getComponent<T>(classConstructor: __types_globals__Constructor<T>): null | T

- ### En

  Returns the component of supplied type if the node has one attached, null if it doesn't.
  You can also get component in the node by passing in the name of the script.

  ### Zh

  获取节点上指定类型的组件，如果节点有附加指定类型的组件，则返回，如果没有则为空。
  传入参数也可以是脚本的名称。

  ### Example

      import { Sprite } from 'cc';
      // get sprite component.
      var sprite = node.getComponent(Sprite);

  #### Type Parameters

  - #### T extends Component<T>

  #### Parameters

  - ##### classConstructor: __types_globals__Constructor<T>

    The class of component to be retrieved or to be created

  #### Returns null | T

  Inherited from AudioSource.getComponent

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25443
- getComponent(className: string): null | Component

- ### En

  Returns the component of supplied type if the node has one attached, null if it doesn't.
  You can also get component in the node by passing in the name of the script.

  ### Zh

  获取节点上指定类型的组件，如果节点有附加指定类型的组件，则返回，如果没有则为空。
  传入参数也可以是脚本的名称。

  ### Example

      // get custom test calss.
      var test = node.getComponent("Test");

  #### Parameters

  - ##### className: string

    A string for the class name of the component

  #### Returns null | Component

  Inherited from AudioSource.getComponent

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25458

### getComponentInChildren

- getComponentInChildren<T>(classConstructor: __types_globals__Constructor<T>): null | T

- ### En

  Returns the component of supplied type in any of its children using depth first search.

  ### Zh

  递归查找所有子节点中第一个匹配指定类型的组件。

  ### Example

      import { Sprite } from 'cc';
      const sprite = node.getComponentInChildren(Sprite);

  #### Type Parameters

  - #### T extends Component<T>

  #### Parameters

  - ##### classConstructor: __types_globals__Constructor<T>

    The class of component to be retrieved

  #### Returns null | T

  Inherited from AudioSource.getComponentInChildren

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25490
- getComponentInChildren(className: string): null | Component

- ### En

  Returns the component of supplied type in any of its children using depth first search.

  ### Zh

  递归查找所有子节点中第一个匹配指定类型的组件。

  ### Example

      var Test = node.getComponentInChildren("Test");

  #### Parameters

  - ##### className: string

    A string for the class name of the component

  #### Returns null | Component

  Inherited from AudioSource.getComponentInChildren

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25500

### getComponents

- getComponents<T>(classConstructor: __types_globals__Constructor<T>): T[]

- ### En

  Returns all components of supplied type in the node.

  ### Zh

  返回节点上指定类型的所有组件。

  ### Example

      import { Sprite } from 'cc';
      const sprites = node.getComponents(Sprite);

  #### Type Parameters

  - #### T extends Component<T>

  #### Parameters

  - ##### classConstructor: __types_globals__Constructor<T>

    The class of components to be retrieved

  #### Returns T[]

  Inherited from AudioSource.getComponents

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25469
- getComponents(className: string): Component[]

- ### En

  Returns all components of supplied type in the node.

  ### Zh

  返回节点上指定类型的所有组件。

  ### Example

      const tests = node.getComponents("Test");

  #### Parameters

  - ##### className: string

    A string for the class name of the components

  #### Returns Component[]

  Inherited from AudioSource.getComponents

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25479

### getComponentsInChildren

- getComponentsInChildren<T>(classConstructor: __types_globals__Constructor<T>): T[]

- ### En

  Returns all components of supplied type in self or any of its children.

  ### Zh

  递归查找自身或所有子节点中指定类型的组件。

  ### Example

      import { Sprite } from 'cc';
      const sprites = node.getComponentsInChildren(Sprite);

  #### Type Parameters

  - #### T extends Component<T>

  #### Parameters

  - ##### classConstructor: __types_globals__Constructor<T>

    The class of components to be retrieved

  #### Returns T[]

  Inherited from AudioSource.getComponentsInChildren

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25511
- getComponentsInChildren(className: string): Component[]

- ### En

  Returns all components of supplied type in self or any of its children.

  ### Zh

  递归查找自身或所有子节点中指定类型的组件。

  ### Example

      const tests = node.getComponentsInChildren("Test");

  #### Parameters

  - ##### className: string

    A string for the class name of the components

  #### Returns Component[]

  Inherited from AudioSource.getComponentsInChildren

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25521

### getPCMData

- getPCMData(channelIndex: number): Promise<undefined | AudioPCMDataView>

- ### En

  Get PCM data from specified channel. Currently it is only available in Native platform and Web Audio (including Web and ByteDance platforms).

  ### Zh

  通过指定的通道获取音频的 PCM data。 目前仅在原生平台和 Web Audio（包括 Web 和 字节平台）中可用。

  ### Returns

  A Promise to get the PCM data after audio is loaded.

  ### Example

      audioSource.getPCMData(0).then(dataView => {
        if (!dataView)  return;
        for (let i = 0; i < dataView.length; ++i) {
          console.log('data: ' + dataView.getData(i));
        }
      });

  #### Parameters

  - ##### channelIndex: number

    The channel index. 0 is left channel, 1 is right channel.

  #### Returns Promise<undefined | AudioPCMDataView>

  Inherited from AudioSource.getPCMData

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7534

### getSampleRate

- getSampleRate(): Promise<number>

- ### En

  Get the sample rate of audio. Currently it is only available in Native platform and Web Audio (including Web and ByteDance platforms).

  ### Zh

  获取音频的采样率。 目前仅在原生平台和 Web Audio（包括 Web 和 字节平台）中可用。

  ### Returns

  A Promise to get the sample rate after audio is loaded.

  #### Returns Promise<number>

  Inherited from AudioSource.getSampleRate

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7546

### `Protected` `Optional` lateUpdate

- lateUpdate(dt: number): void

- ### En

  LateUpdate is called every frame, if the Component is enabled.
  This is a lifecycle method. It may not be implemented in the super class.
  You can only call its super class method inside it. It should not be called manually elsewhere.

  ### Zh

  如果该组件启用，则每帧调用 LateUpdate。
  该方法为生命周期方法，父类未必会有实现。并且你只能在该方法内部调用父类的实现，不可在其它地方直接调用该方法。

  #### Parameters

  - ##### dt: number

    the delta time in seconds it took to complete the last frame

  #### Returns void

  Inherited from AudioSource.lateUpdate

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25599

### load

- load(url: string, callback?: Function): void

- 加载音乐并播放

  #### Parameters

  - ##### url: string

    音乐资源地址

  - ##### `Optional` callback: Function

    加载完成回调

  #### Returns void

  - Defined in assets/core/common/audio/AudioMusic.ts:41

### onDestroy

- onDestroy(): void

- #### Returns void

  Inherited from AudioSource.onDestroy

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7511

### onDisable

- onDisable(): void

- #### Returns void

  Inherited from AudioSource.onDisable

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7510

### onEnable

- onEnable(): void

- #### Returns void

  Inherited from AudioSource.onEnable

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7509

### `Optional` onFocusInEditor

- onFocusInEditor(): void

- #### Returns void

  Inherited from AudioSource.onFocusInEditor

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25658

### onLoad

- onLoad(): void

- #### Returns void

  Inherited from AudioSource.onLoad

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7508

### `Optional` onLostFocusInEditor

- onLostFocusInEditor(): void

- #### Returns void

  Inherited from AudioSource.onLostFocusInEditor

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25659

### `Protected` `Optional` onRestore

- onRestore(): void

- ### En

  onRestore is called after the user clicks the Reset item in the Inspector's context menu or performs an undo operation on this component.
  If the component contains the "internal state", short for "temporary member variables which not included
  in its CCClass properties", then you may need to implement this function.
  The editor will call the getset accessors of your component to record/restore the component's state
  for undo/redo operation. However, in extreme cases, it may not works well. Then you should implement
  this function to manually synchronize your component's "internal states" with its public properties.
  Once you implement this function, all the getset accessors of your component will not be called when
  the user performs an undo/redo operation. Which means that only the properties with default value
  will be recorded or restored by editor.
  Similarly, the editor may failed to reset your component correctly in extreme cases. Then if you need
  to support the reset menu, you should manually synchronize your component's "internal states" with its
  properties in this function. Once you implement this function, all the getset accessors of your component
  will not be called during reset operation. Which means that only the properties with default value
  will be reset by editor.

  This function is only called in editor mode.

  ### Zh

  onRestore 是用户在检查器菜单点击 Reset 时，对此组件执行撤消操作后调用的。
  如果组件包含了“内部状态”（不在 CCClass 属性中定义的临时成员变量），那么你可能需要实现该方法。
  编辑器执行撤销/重做操作时，将调用组件的 get set 来录制和还原组件的状态。 然而，在极端的情况下，它可能无法良好运作。
  那么你就应该实现这个方法，手动根据组件的属性同步“内部状态”。 一旦你实现这个方法，当用户撤销或重做时，组件的所有 get set 都不会再被调用。 这意味着仅仅指定了默认值的属性将被编辑器记录和还原。
  同样的，编辑可能无法在极端情况下正确地重置您的组件。
  于是如果你需要支持组件重置菜单，你需要在该方法中手工同步组件属性到“内部状态”。
  一旦你实现这个方法，组件的所有 get set 都不会在重置操作时被调用。 这意味着仅仅指定了默认值的属性将被编辑器重置。
  此方法仅在编辑器下会被调用。

  #### Returns void

  Inherited from AudioSource.onRestore

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25717

### pause

- pause(): void

- ### En

  Pause the clip.

  ### Zh

  暂停播放。

  #### Returns void

  Inherited from AudioSource.pause

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7575

### play

- play(): void

- ### En

  Play the clip.
  Restart if already playing.
  Resume if paused.

  NOTE: On Web platforms, the Auto Play Policy bans auto playing audios at the first time, because the user gesture is required. there are 2 ways to play audios at the first time:

  - play audios in the callback of TOUCH_END or MOUSE_UP event
  - play audios straightly, the engine will auto play audios at the next user gesture.

  ### Zh

  开始播放。
  如果音频处于正在播放状态，将会重新开始播放音频。
  如果音频处于暂停状态，则会继续播放音频。

  注意:在 Web 平台，Auto Play Policy 禁止首次自动播放音频，因为需要发生用户交互之后才能播放音频。 有两种方式实现音频首次自动播放：

  - 在 TOUCH_END 或者 MOUSE_UP 的事件回调里播放音频。
  - 直接播放音频，引擎会在下一次发生用户交互时自动播放。

  #### Returns void

  Inherited from AudioSource.play

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7568

### playOneShot

- playOneShot(clip: AudioClip, volumeScale?: number): void

- ### En

  Plays an AudioClip, and scales volume by volumeScale. The result volume is `audioSource.volume * volumeScale`.

  ### Zh

  以指定音量倍数播放一个音频一次。最终播放的音量为 `audioSource.volume * volumeScale`。

  #### Parameters

  - ##### clip: AudioClip

    The audio clip to be played.

  - ##### `Optional` volumeScale: number

    volume scaling factor wrt. current value.

  #### Returns void

  Inherited from AudioSource.playOneShot

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:7591

### `Private` playPrepare

- playPrepare(url: string, data: AudioClip): void

- #### Parameters

  - ##### url: string

  - ##### data: AudioClip

  #### Returns void

  - Defined in assets/core/common/audio/AudioMusic.ts:65

### release

- release(): void

- 释放当前背景音乐资源

  #### Returns void

  - Defined in assets/core/common/audio/AudioMusic.ts:100

### `Optional` resetInEditor

- resetInEditor(didResetToDefault?: boolean): void

- ### En

  Called to initialize the component or node’s properties when adding the component the first time or when the Reset command is used. This function is only called in editor.

  ### Zh

  用来初始化组件或节点的一些属性，当该组件被第一次添加到节点上或用户点击了它的 Reset 菜单时调用。这个回调只会在编辑器下调用。

  #### Parameters

  - ##### `Optional` didResetToDefault: boolean

  #### Returns void

  Inherited from AudioSource.resetInEditor

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25665

### schedule

- schedule(callback: any, interval?: number, repeat?: number, delay?: number): void

- ### En

  Use Scheduler system to schedule a custom task.
  If the task is already scheduled, then the interval parameter will be updated without scheduling it again.

  ### Zh

  使用定时器系统调度一个自定义的回调任务。
  如果回调任务已调度，那么将不会重复调度它，只会更新时间间隔参数。

  ### Example

      import { log } from 'cc';
      this.schedule((dt) => void log(`time: ${dt}`), 1);

  #### Parameters

  - ##### callback: any

    The callback function of the task

  - ##### `Optional` interval: number

    The time interval between each invocation

  - ##### `Optional` repeat: number

    The repeat count of this task, the task will be invoked (repeat + 1) times, use macro.REPEAT_FOREVER to repeat a task forever

  - ##### `Optional` delay: number

    The delay time for the first invocation, Unit: s

  #### Returns void

  Inherited from AudioSource.schedule

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25548

### scheduleOnce

- scheduleOnce(callback: any, delay?: number): void

- ### En

  Use Scheduler system to schedule a task that runs only once, with a delay of 0 or larger.

  ### Zh

  使用定时器系统调度一个只运行一次的回调任务，可以指定 0 让回调函数在下一帧立即执行或者在一定的延时之后执行。

  ### Method

  scheduleOnce

  ### See

  schedule

  ### Example

      import { log } from 'cc';
      this.scheduleOnce((dt) => void log(`time: ${dt}`), 2);

  #### Parameters

  - ##### callback: any

    The callback function of the task

  - ##### `Optional` delay: number

    The delay time for the first invocation, Unit: s

  #### Returns void

  Inherited from AudioSource.scheduleOnce

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25562

### `Protected` `Optional` start

- start(): void

- ### En

  Called before all scripts' update if the Component is enabled the first time.
  Usually used to initialize some logic which need to be called after all components' `onload` methods called.
  This is a lifecycle method. It may not be implemented in the super class.
  You can only call its super class method inside it. It should not be called manually elsewhere.

  ### Zh

  如果该组件第一次启用，则在所有组件的 update 之前调用。通常用于需要在所有组件的 onLoad 初始化完毕后执行的逻辑。
  该方法为生命周期方法，父类未必会有实现。并且你只能在该方法内部调用父类的实现，不可在其它地方直接调用该方法。

  #### Returns void

  Inherited from AudioSource.start

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25633

### stop

- stop(): void

- 停止音乐播放

  #### Returns void

  Overrides AudioSource.stop

  - Defined in assets/core/common/audio/AudioMusic.ts:60

### unschedule

- unschedule(callback_fn: any): void

- ### En

  Un-schedules a custom task.

  ### Zh

  取消调度一个自定义的回调任务。

  ### Example

      this.unschedule(_callback);

  #### Parameters

  - ##### callback_fn: any

    The callback function of the task

  #### Returns void

  Inherited from AudioSource.unschedule

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25572

### unscheduleAllCallbacks

- unscheduleAllCallbacks(): void

- ### En

  unschedule all scheduled tasks.

  ### Zh

  取消调度所有已调度的回调函数。

  ### Example

      this.unscheduleAllCallbacks();

  #### Returns void

  Inherited from AudioSource.unscheduleAllCallbacks

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:25581

### update

- update(dt: number): void

- cc.Component 生命周期方法，验证背景音乐播放完成逻辑，建议不要主动调用

  #### Parameters

  - ##### dt: number

  #### Returns void

  Overrides AudioSource.update

  - Defined in assets/core/common/audio/AudioMusic.ts:85

### `Static` _deferredDestroy

- _deferredDestroy(): void

- #### Returns void

  Inherited from AudioSource._deferredDestroy

  - Defined in ../../../../cocos_editor/Creator/3.8.3/resources/resources/3d/engine/bin/.declarations/cc.d.ts:20873

Generated using TypeDoc