Cocos Creator API

1.4.x

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

audioEngine static

Module: cc

cc.audioEngine is the singleton object, it provide simple audio APIs.

Methods

play
(
  • filePath
  • loop
  • volume
)
Number

Play audio.

name type description
filePath String

The path of the audio file without filename extension.

loop Boolean

Whether the music loop or not.

volume Number

Volume size.

returns:

type: Number

audioId

examples:

//example
var audioID = cc.audioEngine.play(path, false, 0.5);

setLoop
(
  • audioID
  • loop
)

Set audio loop.

name type description
audioID Number

audio id.

loop Boolean

Whether cycle.

examples:

//example
cc.audioEngine.setLoop(id, true);

isLoop
(
  • audioID
)
Boolean

Get audio cycle state.

name type description
audioID Number

audio id.

returns:

type: Boolean

Whether cycle.

examples:

//example
cc.audioEngine.isLoop(id);

setVolume
(
  • audioID
  • volume
)

Set the volume of audio.

name type description
audioID Number

audio id.

volume Number

Volume must be in 0.0~1.0 .

examples:

//example
cc.audioEngine.setVolume(id, 0.5);

getVolume
(
  • audioID
)
Boolean

The volume of the music max value is 1.0,the min value is 0.0 .

name type description
audioID Number

audio id.

returns:

type: Boolean

examples:

//example
var volume = cc.audioEngine.getVolume(id);

setCurrentTime
(
  • audioID
  • sec
)
Boolean

Set current time

name type description
audioID Number