public class

SoundPlayer

extends Object
java.lang.Object
   ↳ sofia.audio.SoundPlayer

Class Overview

This class provides a simple interface for playing basic sounds (such as notification chimes or game play effects) in a Sofia application.

Summary

Public Constructors
SoundPlayer(Context context)
Creates a new SoundPlayer with given context (which is an activity or screen).
Public Methods
void loadSound(String name)
Attempts to load the sound file with the given name by first checking for a resource with the matching name in res/raw, and if it is not found there then it is looked up in the assets/sounds folder.
void pause(String name)
Pauses the sound with the specified name, if it is playing.
void pauseAll()
Pauses all currently playing sounds.
void play(String name, int loopCount)
Plays the sound with the specified name, repeating it a given number of times.
void play(String name)
Plays the sound with the specified name once.
void playForever(String name)
Plays the sound with the specified name, repeating it forever (until a method such as pause(String) or stop(String) is called).
void resume(String name)
Resumes the sound with the specified name, if it is paused.
void resumeAll()
Resumes all sounds that were playing when pauseAll() was called.
void stop(String name)
Stops the sound with the specified name, if it is currently playing.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public SoundPlayer (Context context)

Creates a new SoundPlayer with given context (which is an activity or screen).

Parameters
context the context

Public Methods

public void loadSound (String name)

Attempts to load the sound file with the given name by first checking for a resource with the matching name in res/raw, and if it is not found there then it is looked up in the assets/sounds folder.

Parameters
name the name of the sound file, without the file extension
Throws
IllegalArgumentException if a sound with the given name cannot be located

public void pause (String name)

Pauses the sound with the specified name, if it is playing. If the sound is not playing, nothing happens.

Parameters
name the name of the sound to pause

public void pauseAll ()

Pauses all currently playing sounds. Call resumeAll() to start them again where they left off.

public void play (String name, int loopCount)

Plays the sound with the specified name, repeating it a given number of times.

Parameters
name the name of the sound to play
loopCount the number of times to repeat the sound

public void play (String name)

Plays the sound with the specified name once.

Parameters
name the name of the sound to play

public void playForever (String name)

Plays the sound with the specified name, repeating it forever (until a method such as pause(String) or stop(String) is called).

Parameters
name the name of the sound to play

public void resume (String name)

Resumes the sound with the specified name, if it is paused. If the sound is not paused (or was never loaded), nothing happens.

Parameters
name the name of the sound to resume

public void resumeAll ()

Resumes all sounds that were playing when pauseAll() was called.

public void stop (String name)

Stops the sound with the specified name, if it is currently playing. If the sound is not currently playing, nothing happens.

Parameters
name the name of the sound to stop