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). | |
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.
|
inline |
Constructs a MiniAudioPlayer object and initializes the MiniAudio engine.
Initializes the engine and prepares the player for loading and playing audio.
std::runtime_error | If the MiniAudio engine cannot be initialized. |
|
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.
|
inline |
Gets the total duration of the sound in seconds.
This method retrieves the total duration of the loaded audio file in seconds.
std::runtime_error | If the duration cannot be retrieved. |
|
inline |
Gets the current volume of the audio playback.
This method retrieves the current volume level of the sound playback.
|
inline |
Checks if the sound is currently playing.
This method returns whether the sound is currently playing.
true
if the sound is playing, false
otherwise.
|
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.
filePath | The path to the audio file to load. |
std::runtime_error | If the audio file cannot be loaded. |
|
inline |
Pauses the current audio playback.
This method pauses playback and stores the current position to allow resumption from the same point.
std::runtime_error | If pausing the sound fails. |
|
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.
std::runtime_error | If playback cannot be started. |
|
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.
|
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.
seconds | The time (in seconds) to seek to. |
|
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).
volume | The volume to set. |
std::invalid_argument | If the volume is outside the valid range of 0.0 to 1.0. |
|
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.