mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2025-12-11 12:48:12 +08:00
use state machine to manage player state
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user