Files
go-mxl-player/internal/playback/state.go
T
2026-08-27 23:33:04 +03:00

69 lines
992 B
Go

package playback
import (
"fmt"
"time"
)
type Unit uint8
const (
UnitVideo Unit = iota
UnitAudio
UnitSync
)
type State uint8
const (
StateIdle State = iota
StateConnecting
StatePlaying
StateReconnecting
StateFailed
StateStopping
)
type Status struct {
Unit Unit
State State
Attempt int
FailedAttempts int
RetryIn time.Duration
Err error
}
type StatusObserver func(Status)
func (u Unit) String() string {
switch u {
case UnitVideo:
return "video"
case UnitAudio:
return "audio"
case UnitSync:
return "sync"
default:
return fmt.Sprintf("Unit(%d)", uint8(u))
}
}
func (s State) String() string {
switch s {
case StateIdle:
return "idle"
case StateConnecting:
return "connecting"
case StatePlaying:
return "playing"
case StateReconnecting:
return "reconnecting"
case StateFailed:
return "failed"
case StateStopping:
return "stopping"
default:
return fmt.Sprintf("State(%d)", uint8(s))
}
}