Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
keshon committed Feb 26, 2024
1 parent f68a230 commit c43432b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
28 changes: 10 additions & 18 deletions mod-music/player/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,38 +92,30 @@ func (p *Player) Play(startAt int, song *Song) {
}

if p.GetCurrentSong().Source != SourceStream {
if p.GetCurrentStatus() != StatusPlaying {
return
}
// handle song
slog.Warn("Song got done signal, checking if should restart")

songDuration, songPosition := p.getSongMetrics(p.GetEncodingSession(), p.GetStreamingSession(), p.GetCurrentSong())

if p.GetEncodingSession().Stats().Duration.Seconds() > 0 && songPosition.Seconds() > 0 && songPosition < songDuration {
startAt := songPosition.Seconds()
slog.Warn("Track should be continue starting from ", startAt)
slog.Warn("Restarting from interrupted position...")

p.GetEncodingSession().Cleanup()
p.GetVoiceConnection().Speaking(false)

slog.Errorf("Current song should not be empty", p.GetCurrentSong())
slog.Warnf("Restarting song %v from interrupted position %v", p.GetCurrentSong().Title, int(startAt))
p.Play(int(startAt), p.GetCurrentSong())

}
} else {
// handle stream
slog.Warn("Stream got done signal")

// p.GetEncodingSession().Cleanup()
// p.GetVoiceConnection().Speaking(false)

// if p.GetCurrentSong() != nil {
// slog.Errorf("Current song should not be empty", p.GetCurrentSong())
// p.Play(startAt, p.GetCurrentSong())
// } else {
// slog.Warn("No songs in the queue to restart from.")
// p.SetCurrentStatus(StatusResting)
// }
slog.Warn("Stream got done signal, should always restart")

p.GetEncodingSession().Cleanup()
p.GetVoiceConnection().Speaking(false)

slog.Warnf("Restarting stream %v", p.GetCurrentSong().Title)
p.Play(0, p.GetCurrentSong())
}

h := history.NewHistory()
Expand Down
4 changes: 2 additions & 2 deletions mod-music/player/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func (p *Player) ClearQueue() {
slog.Warn("Player")
slog.Info("Clearing song queue...")

// p.Lock()
// defer p.Unlock()
p.Lock()
defer p.Unlock()
if p.GetSongQueue() == nil {
return
}
Expand Down

0 comments on commit c43432b

Please sign in to comment.