| 48 | } |
| 49 | |
| 50 | func NewTimerPlayer(seconds int, name string) (*TimerPlayer, error) { |
| 51 | if seconds <= 0 { |
| 52 | return nil, fmt.Errorf("duration must be positive") |
| 53 | } |
| 54 | |
| 55 | fps := CalculateFps() |
| 56 | interval := baseInterval |
| 57 | if time.Second*time.Duration(seconds) > lowPresicionAfter { |
| 58 | log.Printf("low precision requested, duration > %d", lowPresicionAfter) |
| 59 | interval += interval / 2 |
| 60 | } |
| 61 | |
| 62 | return &TimerPlayer{ |
| 63 | Name: name, |
| 64 | duration: time.Duration(seconds) * time.Second, |
| 65 | objectPath: "/org/mpris/MediaPlayer2", |
| 66 | playbackStatus: "Playing", |
| 67 | interval: interval, |
| 68 | fps: fps, |
| 69 | tickerDone: make(chan struct{}), |
| 70 | emitter: make(chan PropsChangedEvent, 1), |
| 71 | Done: make(chan struct{}, 1), |
| 72 | }, nil |
| 73 | } |
| 74 | |
| 75 | func (p *TimerPlayer) AddSubscription(onProgress func(event PropsChangedEvent)) { |
| 76 | p.subscribers = append(p.subscribers, onProgress) |