use state machine to manage player state

This commit is contained in:
aynakeya
2025-08-07 01:09:07 +08:00
parent 3aebdb00f9
commit 5a699a1e2e
9 changed files with 105 additions and 50 deletions

View File

@@ -4,3 +4,27 @@ type AudioDevice struct {
Name string
Description string
}
type PlayerState int
const (
PlayerStatePlaying PlayerState = iota
PlayerStateLoading
PlayerStateIdle
)
func (s PlayerState) NextState(next PlayerState) PlayerState {
if s == PlayerStatePlaying {
return next
}
if s == PlayerStateIdle {
return next
}
if s == PlayerStateLoading {
if next != PlayerStatePlaying {
return PlayerStateLoading
}
return next
}
return next
}