Added set playback time

This commit is contained in:
2025-09-09 02:45:42 +03:00
parent 640f6af291
commit 57b8bfa719
2 changed files with 19 additions and 2 deletions

View File

@@ -22,9 +22,9 @@ public:
void Reset(); void Reset();
SoundState GetState(); SoundState GetState();
float GetDuration();
float GetPlaybackTime(); float GetPlaybackTime();
bool SetRuntime(); bool SetPlaybackTime(float time);
float GetDuration();
void SetPosition(Magnum::Vector3 position); void SetPosition(Magnum::Vector3 position);
Magnum::Vector3 GetPosition(); Magnum::Vector3 GetPosition();
void SetVolume(float value); void SetVolume(float value);

View File

@@ -1,4 +1,5 @@
#include "ChargeAudio.hpp" #include "ChargeAudio.hpp"
#include <Corrade/Utility/Debug.h>
#include <Magnum/Magnum.h> #include <Magnum/Magnum.h>
#include <Magnum/Math/Vector3.h> #include <Magnum/Math/Vector3.h>
@@ -38,6 +39,22 @@ float Sound::GetPlaybackTime() {
ma_sound_get_cursor_in_seconds(&this->maSound, &time); ma_sound_get_cursor_in_seconds(&this->maSound, &time);
return time; return time;
} }
// true or false depending on if the playback was set
bool Sound::SetPlaybackTime(float time) {
// Better to just catch it from the start
if (time < 0) {
return false;
}
bool result = ma_sound_seek_to_second(&maSound, time) != MA_SUCCESS;
if (result) {
Utility::Error{} << "Failed to set playback time to " << time
<< " on a sound instance";
}
return result;
}
// Controls // Controls
void Sound::Play() { void Sound::Play() {
ma_sound_start(&maSound); ma_sound_start(&maSound);