Cocos Creator API

1.4.x

Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.

AudioSource

Extends Component
Module: cc

Audio Source.

Properties

isPlaying Boolean readOnly

Is the audio source playing (Read Only).
Note: isPlaying is not supported for Native platforms.

clip AudioClip

The clip of the audio source.

volume Number

The volume of the audio source.

mute Boolean

Is the audio source mute?

loop Boolean

Is the audio source looping?

playOnLoad Boolean

If set to true, the audio source will automatically start playing on onLoad.

__eventTargets Array private

Inherited from Component:

Register all related EventTargets, all event callbacks will be removed in _onPreDestroy

node Node

Inherited from Component:

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

examples:

cc.log(comp.node);

uuid String readOnly

Inherited from Component:

The uuid for editor.

examples:

cc.log(comp.uuid);

_enabled Boolean private

Inherited from Component:

enabled Boolean

Inherited from Component:

indicates whether this component is enabled or not.

examples:

comp.enabled = true;
cc.log(comp.enabled);

enabledInHierarchy Boolean readOnly

Inherited from Component:

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

examples:

cc.log(comp.enabledInHierarchy);

_isOnLoadCalled Boolean readOnly

Inherited from Component:

TODO

examples:

cc.log(_isOnLoadCalled);

_name String private

_objFlags Number private

name String

The name of the object.

examples:

obj.name = "New Obj";

isValid Boolean readOnly

Indicates whether the object is not yet destroyed.

examples:

cc.log(obj.isValid);

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

Methods

play ( )

Plays the clip.

stop ( )

Stops the clip.

pause ( )

Pause the clip.

resume ( )

Resume the clip.

rewind ( )

Rewind playing music.

getCurrentTime ( )

Get current time

setCurrentTime
(
  • time
)

Set current time

name type description
time Number

getDuration ( )

Get audio duration

update ( )

Inherited from Component:

Update is called every frame, if the Component is enabled.

lateUpdate ( )

Inherited from Component:

LateUpdate is called every frame, if the Component is enabled.

__preload ( ) private

Inherited from Component:

__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.

onLoad ( )

Inherited from Component: