JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SoundFile Class Reference

Sound loaded from an OGG file. More...

#include <jngl/SoundFile.hpp>

Public Member Functions

 SoundFile (const std::string &filename, std::launch policy=std::launch::async)
 Load an OGG file called filename.
 
 SoundFile (const SoundFile &)=delete
 
SoundFileoperator= (const SoundFile &)=delete
 
 SoundFile (SoundFile &&) noexcept
 
SoundFileoperator= (SoundFile &&) noexcept
 
void play ()
 Play the sound once. If called twice the sound would also play twice.
 
void play (Channel &)
 Play the sound once on the Channel.
 
void stop ()
 Stop the last started sound.
 
void stop (Channel &)
 Stop the last started sound of this SoundFile started on the Channel.
 
bool isPlaying ()
 Whether the sound is still playing at least once.
 
void loop ()
 Play the sound in a loop. Can also be stopped using stop()
 
void loop (Channel &)
 
void setVolume (float v)
 Set volume in [0, ∞]. Default is 1.0f.
 
void load ()
 Block until the sound file has been fully decompressed and loaded.
 
std::chrono::milliseconds length () const
 Returns the duration in ms.
 
float progress () const
 Returns playing progress in [0, 1], can be used with length() to determine how much time has passed.
 

Detailed Description

Sound loaded from an OGG file.

JNGL keeps a list of loaded sound files, so there's no need for you to use this class directly - you can just use jngl::play or Channel::play.

Definition at line 29 of file SoundFile.hpp.

Constructor & Destructor Documentation

◆ SoundFile()

SoundFile ( const std::string & filename,
std::launch policy = std::launch::async )
explicit

Load an OGG file called filename.

Loading can either happen on its own thread (std::launch::async) or the first time you try to play the file (std::launch::deferred).

Note
If the file doesn't exist this will not throw, but calling SoundFile::play, SoundFile::loop or SoundFile::load will.

Member Function Documentation

◆ stop()

void stop ( Channel & )

Stop the last started sound of this SoundFile started on the Channel.

Note
If not using the main Channel (i.e. Channel::main()), this method should be used instead of stop().

◆ load()

void load ( )

Block until the sound file has been fully decompressed and loaded.

Exceptions
std::runtime_errorFile not found or decoding errors

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