AudioPlayer Class
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
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
BooleanIf 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
StringName 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
IntegerValue 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.