Skip to content

Commit 5068a6a

Browse files
committed
Engine: fixed SoundClip not updating position on PlayFrom() call
1 parent 6420630 commit 5068a6a

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

Engine/media/audio/audioplayer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ void AudioPlayer::Init()
3333
success = _decoder->Seek(_onLoadPositionMs) == _onLoadPositionMs;
3434
else
3535
success = _decoder->Open(_onLoadPositionMs);
36+
_source->SetPlaybackPosMs(_decoder->GetPositionMs());
3637
_playState = success ? _onLoadPlayState : PlayStateError;
3738
if (_playState == PlayStatePlaying)
3839
_source->Play();
@@ -123,6 +124,7 @@ void AudioPlayer::Seek(float pos_ms)
123124
{
124125
case PlayStateInitial:
125126
_onLoadPositionMs = pos_ms;
127+
Init(); // make sure the decoder opens and seeks, update posMs
126128
break;
127129
case PlayStatePlaying:
128130
case PlayStatePaused:

Engine/media/audio/soundclip.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ int SoundClip::play()
5757
return true;
5858
}
5959

60+
int SoundClip::play_from(int position)
61+
{
62+
seek(position);
63+
return play();
64+
}
65+
6066
void SoundClip::pause()
6167
{
6268
if (!is_ready())

Engine/media/audio/soundclip.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class SoundClip final
5555
int maximumPossibleDistanceAway;
5656

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

71-
inline int play_from(int position)
72-
{
73-
seek(position);
74-
return play();
75-
}
76-
7772
// Gets if the clip is valid (playing or ready to play)
7873
inline bool is_ready() const
7974
{

0 commit comments

Comments
 (0)