Skip to content

Commit 4d8d504

Browse files
committed
Let play return SoundFile&
1 parent 8c3bedf commit 4d8d504

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/jngl/SoundFile.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ SoundFile::SoundFile(const std::string& filename, std::launch)
9494
// fclose() the FILE * pointer itself.
9595
throw std::runtime_error("Could not open OGG file (" + filename + ").");
9696
}
97-
Finally cleanup(
98-
[&oggFile]()
99-
{
97+
Finally cleanup([&oggFile]() {
10098
ov_clear(&oggFile); /* calls fclose */
10199
});
102100

@@ -262,8 +260,10 @@ std::shared_ptr<SoundFile> Audio::getSoundFile(std::string_view filename, std::l
262260
.first->second;
263261
}
264262

265-
void play(const std::string& filename) {
266-
Audio::handle().getSoundFile(filename, std::launch::deferred)->play();
263+
SoundFile& play(const std::string& filename) {
264+
auto soundFile = Audio::handle().getSoundFile(filename, std::launch::deferred);
265+
soundFile->play();
266+
return *soundFile;
267267
}
268268

269269
void stop(const std::string& filename) {

src/jngl/sound.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ float getVolume();
1818
/// Play an OGG audio file once
1919
///
2020
/// Might block if the file hasn't been played before. To avoid that use jngl::load before.
21-
void play(const std::string& filename);
21+
///
22+
/// Example:
23+
/// \code
24+
/// jngl::play("sfx/foo.ogg").setVolume(0.2);
25+
/// \endcode
26+
SoundFile& play(const std::string& filename);
2227

2328
/// Stop an OGG audio file if it's currently playing
2429
void stop(const std::string& filename);

0 commit comments

Comments
 (0)