Documentation
¶
Overview ¶
Package playlistmemory remembers where each playlist was left, which playlists were open when Core stopped, and how far into long audio tracks playback got. Writes go through one background writer so the queue handler never waits on the database.
Index ¶
- Constants
- func Resumable(position, length time.Duration) bool
- type Memory
- func (m *Memory) Flush(ctx context.Context)
- func (m *Memory) Forget(pls *playlists.Playlist)
- func (m *Memory) ForgetPosition(profileID, systemID, path string)
- func (m *Memory) OpenPlaylists() []*playlists.Playlist
- func (m *Memory) PlaylistChanged(slot string, pls *playlists.Playlist)
- func (m *Memory) Prepare(pls *playlists.Playlist, start int)
- func (m *Memory) ResumeAt(systemID, path string) (position, length time.Duration)
- func (m *Memory) SavePosition(profileID, systemID, path string, position, length time.Duration)
- func (m *Memory) Start()
- func (m *Memory) Stop()
- type PositionTracker
Constants ¶
const ( // KeepPlaylists is how many playlists each profile remembers. KeepPlaylists = 200 // KeepPositions is how many track positions each profile remembers. KeepPositions = 200 )
const ( // MinResumeLength is the shortest track whose position is kept. Shorter // tracks are songs, which always play from the start. MinResumeLength = 10 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is the playlist and position memory of one device. A nil Memory remembers nothing, which is what a database without the capability gets.
func New ¶
func New(store database.PlaylistMemoryStore, activeProfile func() string) *Memory
New returns the memory backed by store, or nil when store is nil. activeProfile returns the active profile's ID, "" for none.
func (*Memory) Forget ¶
Forget starts a playlist over the next time it loads, as when it played to its natural end.
func (*Memory) ForgetPosition ¶
ForgetPosition queues forgetting how far into a track a profile got.
func (*Memory) OpenPlaylists ¶
OpenPlaylists returns the playlists that were open when Core last stopped and belong to the active profile, paused.
func (*Memory) PlaylistChanged ¶
PlaylistChanged records the playlist now in slot, nil when the slot was closed: where the playlist is, for the profile that loaded it, and what to reopen after a restart. It never blocks, so it is safe to call while the caller holds its own lock.
func (*Memory) Prepare ¶
Prepare readies a playlist that was just loaded: it belongs to the active profile, and it opens where that profile left it. An explicit start, counted from 1, wins over the memory. Nothing is attached when the remembered item cannot be told apart from another, or is gone.
func (*Memory) ResumeAt ¶
ResumeAt returns how far into the track at systemID and path the active profile got, and how long the track was then. It is zero when there is nothing to resume.
func (*Memory) SavePosition ¶
SavePosition queues how far into a track a profile got.
type PositionTracker ¶
type PositionTracker struct {
// contains filtered or unexported fields
}
PositionTracker keeps the position of long native audio tracks on the primary slot. A track belongs to the profile active when it started. A nil tracker does nothing.
func NewPositionTracker ¶
func NewPositionTracker( memory *Memory, playback audio.PlaybackManager, media func() *models.ActiveMedia, clock clockwork.Clock, ) *PositionTracker
NewPositionTracker returns a tracker sampling playback for the media media reports. clock may be nil for the real clock.
func (*PositionTracker) Finished ¶
func (t *PositionTracker) Finished(path string)
Finished forgets the position of a track that played to its end.
func (*PositionTracker) Sample ¶
func (t *PositionTracker) Sample()
Sample reads the playing track and saves its position when it paused, changed or stopped, or has played on for a while since the last save.
func (*PositionTracker) Start ¶
func (t *PositionTracker) Start()
Start samples playback until Stop. It does nothing without memory or playback.
func (*PositionTracker) Stop ¶
func (t *PositionTracker) Stop()
Stop saves where the playing track is and stops sampling. Call it before playback is torn down.