reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

Plays sound files. More...

#include <ofSoundPlayer.h>

Inheritance diagram for ofSoundPlayer:
ofBaseSoundPlayer

Public Member Functions

 ofSoundPlayer ()
 
void setPlayer (std::shared_ptr< ofBaseSoundPlayer > newPlayer)
 
std::shared_ptr< ofBaseSoundPlayergetPlayer ()
 
bool load (const of::filesystem::path &fileName, bool stream=false)
 Tells the sound player which file to play.
 
 OF_DEPRECATED_MSG ("Use load", bool loadSound(std::string fileName, bool stream=false))
 
void unload ()
 Stops and unloads the current sound.
 
 OF_DEPRECATED_MSG ("Use unload", void unloadSound())
 
void play ()
 Starts playback.
 
void stop ()
 Stops playback.
 
void setVolume (float vol)
 Sets playback volume.
 
void setPan (float pan)
 Sets stereo pan.
 
void setSpeed (float speed)
 Sets playback speed.
 
void setPaused (bool paused)
 Enables pause / resume.
 
void setLoop (bool loop)
 Sets whether to loop once the end of the file is reached.
 
void setMultiPlay (bool multiplay)
 Enables playing multiple simultaneous copies of the sound.
 
void setPosition (float percent)
 Sets position of the playhead within the file (aka "seeking").
 
void setPositionMS (int ms)
 Sets position of the playhead within the file (aka "seeking").
 
int getPositionMS () const
 Gets position of the playhead.
 
float getPosition () const
 Gets position of the playhead.
 
bool isPlaying () const
 Gets current playback state.
 
 OF_DEPRECATED_MSG ("Use isPlaying", bool getIsPlaying() const)
 
float getSpeed () const
 Gets playback speed.
 
float getPan () const
 Gets stereo pan.
 
float getVolume () const
 Gets current volume.
 
bool isLoaded () const
 Queries the player to see if its file was loaded successfully.
 
- Public Member Functions inherited from ofBaseSoundPlayer
 ofBaseSoundPlayer ()
 
virtual ~ofBaseSoundPlayer ()
 

Protected Attributes

std::shared_ptr< ofBaseSoundPlayerplayer
 

Detailed Description

Plays sound files.

ofSoundPlayer handles simple playback of sound files, with controls for volume, pan, speed, seeking and multiplay. This is a common cross-platform sound player interface which is inherited by each of the platform-specific sound player implementations.

Constructor & Destructor Documentation

◆ ofSoundPlayer()

ofSoundPlayer::ofSoundPlayer ( )

Member Function Documentation

◆ getPan()

float ofSoundPlayer::getPan ( ) const
virtual

Gets stereo pan.

Returns
stereo pan in the range -1 to 1.

Implements ofBaseSoundPlayer.

◆ getPlayer()

std::shared_ptr< ofBaseSoundPlayer > ofSoundPlayer::getPlayer ( )

◆ getPosition()

float ofSoundPlayer::getPosition ( ) const
virtual

Gets position of the playhead.

Returns
playhead position as a float between 0 and 1.

Implements ofBaseSoundPlayer.

◆ getPositionMS()

int ofSoundPlayer::getPositionMS ( ) const
virtual

Gets position of the playhead.

Returns
playhead position in milliseconds.

Implements ofBaseSoundPlayer.

◆ getSpeed()

float ofSoundPlayer::getSpeed ( ) const
virtual

Gets playback speed.

Returns
playback speed (see ofSoundPlayer::setSpeed()).

Implements ofBaseSoundPlayer.

◆ getVolume()

float ofSoundPlayer::getVolume ( ) const
virtual

Gets current volume.

Returns
current volume in the range 0 to 1.

Implements ofBaseSoundPlayer.

◆ isLoaded()

bool ofSoundPlayer::isLoaded ( ) const
virtual

Queries the player to see if its file was loaded successfully.

Returns
whether or not the player is ready to begin playback.

Implements ofBaseSoundPlayer.

◆ isPlaying()

bool ofSoundPlayer::isPlaying ( ) const
virtual

Gets current playback state.

Returns
true if the player is currently playing a file.

Implements ofBaseSoundPlayer.

◆ load()

bool ofSoundPlayer::load ( const of::filesystem::path &  fileName,
bool  stream = false 
)
virtual

Tells the sound player which file to play.

Codec support varies by platform but wav, aif, and mp3 are safe.

Parameters
fileNamePath to the sound file, relative to your app's data folder.
streamset "true" to enable streaming from disk (for large files).

Implements ofBaseSoundPlayer.

◆ OF_DEPRECATED_MSG() [1/3]

ofSoundPlayer::OF_DEPRECATED_MSG ( "Use isPlaying"  ,
bool getIsPlaying() const   
)

◆ OF_DEPRECATED_MSG() [2/3]

ofSoundPlayer::OF_DEPRECATED_MSG ( "Use load"  ,
bool   loadSoundstd::string fileName, bool stream=false 
)

◆ OF_DEPRECATED_MSG() [3/3]

ofSoundPlayer::OF_DEPRECATED_MSG ( "Use unload"  ,
void   unloadSound() 
)

◆ play()

void ofSoundPlayer::play ( )
virtual

Starts playback.

Implements ofBaseSoundPlayer.

◆ setLoop()

void ofSoundPlayer::setLoop ( bool  loop)
virtual

Sets whether to loop once the end of the file is reached.

Parameters
loop"true" to loop, default is false.

Implements ofBaseSoundPlayer.

◆ setMultiPlay()

void ofSoundPlayer::setMultiPlay ( bool  multiplay)
virtual

Enables playing multiple simultaneous copies of the sound.

Parameters
multiplay"true" to enable, default is false.

Implements ofBaseSoundPlayer.

◆ setPan()

void ofSoundPlayer::setPan ( float  pan)
virtual

Sets stereo pan.

Parameters
panrange is -1 to 1 (-1 is full left, 1 is full right).

Implements ofBaseSoundPlayer.

◆ setPaused()

void ofSoundPlayer::setPaused ( bool  paused)
virtual

Enables pause / resume.

Parameters
paused"true" to pause, "false" to resume.

Implements ofBaseSoundPlayer.

◆ setPlayer()

void ofSoundPlayer::setPlayer ( std::shared_ptr< ofBaseSoundPlayer newPlayer)

◆ setPosition()

void ofSoundPlayer::setPosition ( float  percent)
virtual

Sets position of the playhead within the file (aka "seeking").

Parameters
percentrange is 0 (beginning of file) to 1 (end of file).

Implements ofBaseSoundPlayer.

◆ setPositionMS()

void ofSoundPlayer::setPositionMS ( int  ms)
virtual

Sets position of the playhead within the file (aka "seeking").

Parameters
msnumber of milliseconds from the start of the file.

Implements ofBaseSoundPlayer.

◆ setSpeed()

void ofSoundPlayer::setSpeed ( float  speed)
virtual

Sets playback speed.

Parameters
speedset > 1 for faster playback, < 1 for slower playback.

Implements ofBaseSoundPlayer.

◆ setVolume()

void ofSoundPlayer::setVolume ( float  vol)
virtual

Sets playback volume.

Parameters
volrange is 0 to 1.

Implements ofBaseSoundPlayer.

◆ stop()

void ofSoundPlayer::stop ( )
virtual

Stops playback.

Implements ofBaseSoundPlayer.

◆ unload()

void ofSoundPlayer::unload ( )
virtual

Stops and unloads the current sound.

Implements ofBaseSoundPlayer.

Member Data Documentation

◆ player

std::shared_ptr<ofBaseSoundPlayer> ofSoundPlayer::player
protected

The documentation for this class was generated from the following files: