inLimbo
TUI Music Player that keeps you in Limbo.
 
Loading...
Searching...
No Matches
MiniAudioPlayer Class Reference

A class for playing audio using the MiniAudio library. More...

#include <audio_playback.hpp>

Public Member Functions

 MiniAudioPlayer ()
 Constructs a MiniAudioPlayer object and initializes the MiniAudio engine.
 
 ~MiniAudioPlayer ()
 Destroys the MiniAudioPlayer object, stopping any playback and cleaning up resources.
 
int loadFile (const std::string &filePath)
 Loads an audio file for playback.
 
void play ()
 Starts playback of the loaded audio file.
 
void pause ()
 Pauses the current audio playback.
 
void resume ()
 Resumes playback from the last paused position.
 
void stop ()
 Stops the playback and resets the playback position.
 
void setVolume (float volume)
 Sets the volume of the audio playback.
 
float getVolume () const
 Gets the current volume of the audio playback.
 
bool isCurrentlyPlaying ()
 Checks if the sound is currently playing.
 
float getDuration ()
 Gets the total duration of the sound in seconds.
 
double seekTime (int seconds)
 Seeks to a specific time in the audio (in seconds).
 

Detailed Description

A class for playing audio using the MiniAudio library.

This class wraps the functionality of the MiniAudio library to provide methods for loading, playing, pausing, resuming, stopping, adjusting volume, and seeking within an audio file. It manages playback in a separate thread to handle real-time updates on whether the sound is currently playing.

Constructor & Destructor Documentation

◆ MiniAudioPlayer()

MiniAudioPlayer::MiniAudioPlayer ( )
inline

Constructs a MiniAudioPlayer object and initializes the MiniAudio engine.

Initializes the engine and prepares the player for loading and playing audio.

Exceptions
std::runtime_errorIf the MiniAudio engine cannot be initialized.

◆ ~MiniAudioPlayer()

MiniAudioPlayer::~MiniAudioPlayer ( )
inline

Destroys the MiniAudioPlayer object, stopping any playback and cleaning up resources.

This method ensures that the sound is stopped, the engine is uninitialized, and resources are cleaned up.

Member Function Documentation

◆ getDuration()

float MiniAudioPlayer::getDuration ( )
inline

Gets the total duration of the sound in seconds.

This method retrieves the total duration of the loaded audio file in seconds.

Returns
The duration of the sound in seconds.
Exceptions
std::runtime_errorIf the duration cannot be retrieved.

◆ getVolume()

float MiniAudioPlayer::getVolume ( ) const
inline

Gets the current volume of the audio playback.

This method retrieves the current volume level of the sound playback.

Returns
The current volume level.

◆ isCurrentlyPlaying()

bool MiniAudioPlayer::isCurrentlyPlaying ( )
inline

Checks if the sound is currently playing.

This method returns whether the sound is currently playing.

Returns
true if the sound is playing, false otherwise.

◆ loadFile()

int MiniAudioPlayer::loadFile ( const std::string & filePath)
inline

Loads an audio file for playback.

This method loads the audio file into memory for playback. If a file is already loaded, it is unloaded before loading the new file. If the player is currently playing, it stops the playback first.

Parameters
filePathThe path to the audio file to load.
Returns
0 on success, -1 on failure.
Exceptions
std::runtime_errorIf the audio file cannot be loaded.

◆ pause()

void MiniAudioPlayer::pause ( )
inline

Pauses the current audio playback.

This method pauses playback and stores the current position to allow resumption from the same point.

Exceptions
std::runtime_errorIf pausing the sound fails.

◆ play()

void MiniAudioPlayer::play ( )
inline

Starts playback of the loaded audio file.

This method begins playback from the beginning of the audio file. If the audio file is already playing, nothing happens. A playback thread is started to monitor the state of playback.

Exceptions
std::runtime_errorIf playback cannot be started.

◆ resume()

void MiniAudioPlayer::resume ( )
inline

Resumes playback from the last paused position.

This method resumes playback from the position where the sound was paused. If the sound was not paused, nothing happens.

◆ seekTime()

double MiniAudioPlayer::seekTime ( int seconds)
inline

Seeks to a specific time in the audio (in seconds).

This method seeks to a specific position in the audio based on the number of seconds provided.

Parameters
secondsThe time (in seconds) to seek to.
Returns
The actual time (in seconds) that the sound was seeked to.

◆ setVolume()

void MiniAudioPlayer::setVolume ( float volume)
inline

Sets the volume of the audio playback.

This method adjusts the playback volume. The volume is a float between 0.0 (silent) and 1.0 (maximum volume).

Parameters
volumeThe volume to set.
Exceptions
std::invalid_argumentIf the volume is outside the valid range of 0.0 to 1.0.

◆ stop()

void MiniAudioPlayer::stop ( )
inline

Stops the playback and resets the playback position.

This method stops the current playback, resets the playback position to the beginning, and ensures the playback thread is joined.


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