Moscrif API Docs for: 2012q3
Show:

AudioPlayer Class

Library: media

This class provides the ability to play back sounds and music files on a device. By default, this class supports free formats like: wav, ogg and mod but most platforms support also other frequently used formats like mp3.

Example:

// create new player and load source file
this.player = new AudioPlayer();
this.player.openFile("dat://xxx.ogg");
.....
// play sound if nothing is playing
if (!this.player.playing)
    this.player.play();
// otherwise pause playing
else
    this.player.pause();

Item Index

Methods

Methods

this

()

Object constructor creates new instance of AudioPlayer class.

dispose

()

Dispose function releases resource, allocated in memory. For Audio Player object it is for example opened file.

loop

(
  • percent
)

Loop function determines, what happens after the song end. However, this function has to be used before play function.

Parameters:

  • percent Boolean

    If this parameter is set to true, the song will play again.

Example:

// set loop to true - play song again
this.player.loop(true);
// start playing
this.player.play();

openFile

(
  • file
)

Easy way to open file for playing. By default, native system audio formats are supported, at least:

  • .wav - is suitable for short sounds or effects in games or apps
  • .mp3 - is great format for playing music because it is easy (optimized) to CPU or its implemented by underlaying system

In addition, mobile devices can support also other audio formats like acc etc., which means that these formats can also be supported.

Parameters:

  • file String

    Name of file to open.

pause

()

The pause function pauses playing. The next time you use the start function, playback will continue from the time when it was paused.

play

()

This call, starts playing opened file.

seek

(
  • percent
)

Efficient way to rewind plaing song.

Parameters:

  • percent Integer

    Value between 0 and 100. Zero means begin of the song and 100 end of the song.

Example:

//start playing
player.play();
//seek song to the 10% of time
player.seek(10);

stop

()

This function stops the playback.

Properties

duration

Integer

Value expressing the length of songs.

playing

Boolean

When player is playing some file value is true. Otherwise, it is false.

position

Integer

Value between zero and song duration.