Skip to content

Commit

Permalink
Engine: fixed SoundClip not updating position on PlayFrom() call
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Feb 25, 2025
1 parent 6420630 commit 5068a6a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Engine/media/audio/audioplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void AudioPlayer::Init()
success = _decoder->Seek(_onLoadPositionMs) == _onLoadPositionMs;
else
success = _decoder->Open(_onLoadPositionMs);
_source->SetPlaybackPosMs(_decoder->GetPositionMs());
_playState = success ? _onLoadPlayState : PlayStateError;
if (_playState == PlayStatePlaying)
_source->Play();
Expand Down Expand Up @@ -123,6 +124,7 @@ void AudioPlayer::Seek(float pos_ms)
{
case PlayStateInitial:
_onLoadPositionMs = pos_ms;
Init(); // make sure the decoder opens and seeks, update posMs
break;
case PlayStatePlaying:
case PlayStatePaused:
Expand Down
6 changes: 6 additions & 0 deletions Engine/media/audio/soundclip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ int SoundClip::play()
return true;
}

int SoundClip::play_from(int position)
{
seek(position);
return play();
}

void SoundClip::pause()
{
if (!is_ready())
Expand Down
7 changes: 1 addition & 6 deletions Engine/media/audio/soundclip.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SoundClip final
int maximumPossibleDistanceAway;

int play();
int play_from(int position);
void pause();
void resume();
// Seeks to the position, where pos units depend on the audio type
Expand All @@ -68,12 +69,6 @@ class SoundClip final
// Returns if the clip is still playing, otherwise it's finished
bool update();

inline int play_from(int position)
{
seek(position);
return play();
}

// Gets if the clip is valid (playing or ready to play)
inline bool is_ready() const
{
Expand Down

0 comments on commit 5068a6a

Please sign in to comment.