From f0402acfdcb5505a48a34206125b573bfc4e1da3 Mon Sep 17 00:00:00 2001 From: bloeys Date: Sat, 18 Jun 2022 13:35:34 +0400 Subject: [PATCH] Improve PlaySync --- wavy.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wavy.go b/wavy.go index 77ff47f..ed592ec 100644 --- a/wavy.go +++ b/wavy.go @@ -81,15 +81,19 @@ type Sound struct { Info SoundInfo } +//PlayAsync plays the sound in the background and returns func (s *Sound) PlayAsync() { s.Player.Play() } +//PlaySync plays the sound (if its not already playing) and waits for it to finish before returning. func (s *Sound) PlaySync() { - s.Player.Play() - time.Sleep(s.TotalTime()) + if !s.Player.IsPlaying() { + s.Player.Play() + } + time.Sleep(s.RemainingTime()) //Should never run, but just in case TotalTimeMS was a bit inaccurate for s.Player.IsPlaying() { }