SDK Documentation & Reference.Documentation Pdf



NKAudioPlayer


Overview

Used to play audio files bundled in the application

loadFile(fileName)

Loads the content of file specified by fileName parameter and prepares it to play

loadFileFromDocuments(fileName)

Loads the content of file and prepares it to play, looking for given file name in documents folder

play()

starts to play loaded file

stop()

stops currently playing audio

pause()

pauses currently played audio

resume()

resumes playback from paused state

getDurationInSeconds()

returns integer value specifying duration in seconds of the loaded audio

setPositionInSeconds(seconds)

sets playback position in seconds

getCurrentPositionInSeconds()

returns current position measured in seconds

setPlayingFinishedCallback(callback)

Used to get information about when playback finished Parameters: callback - function name to be called when playback finished

setLoopMode(isInLoop)

set's if player should repeat loaded file, can take argument "yes", "no", "1" and "0"

setVolume(volume)

set's current volume for player, parameter has to be in range [0..100]

dispose()

disposes resources allocated for player

setIgnoreLock(isIgnored)

if this function is set to "yes" then application will still continue to play even if user locked the phone.

Example:

page1.html:
var player1 = new NKAudioPlayer();
player1.loadFile("music.mp3");
var settings = new NKSettings();
settings.setValueForKey(player_id,”playerID”);
//save player1.id in NKSettings
page2.html:
var player2 = new NKAudioPlayer();
player2.dispose(); // release second's player resources as we will use resources of the first player
var settings = new NKSettings();
player2.id = settings.getValueForKey(“playerID”);
player2.play(); // launch play of the first player