playlistmemory

package
v2.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

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

View Source
const (
	// KeepPlaylists is how many playlists each profile remembers.
	KeepPlaylists = 200
	// KeepPositions is how many track positions each profile remembers.
	KeepPositions = 200
)
View Source
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

func Resumable

func Resumable(position, length time.Duration) bool

Resumable reports whether a track of length stopped at position picks up there next time.

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) Flush

func (m *Memory) Flush(ctx context.Context)

Flush waits until every write queued before it is done, or ctx ends.

func (*Memory) Forget

func (m *Memory) Forget(pls *playlists.Playlist)

Forget starts a playlist over the next time it loads, as when it played to its natural end.

func (*Memory) ForgetPosition

func (m *Memory) ForgetPosition(profileID, systemID, path string)

ForgetPosition queues forgetting how far into a track a profile got.

func (*Memory) OpenPlaylists

func (m *Memory) OpenPlaylists() []*playlists.Playlist

OpenPlaylists returns the playlists that were open when Core last stopped and belong to the active profile, paused.

func (*Memory) PlaylistChanged

func (m *Memory) PlaylistChanged(slot string, pls *playlists.Playlist)

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

func (m *Memory) Prepare(pls *playlists.Playlist, start int)

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

func (m *Memory) ResumeAt(systemID, path string) (position, length time.Duration)

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

func (m *Memory) SavePosition(profileID, systemID, path string, position, length time.Duration)

SavePosition queues how far into a track a profile got.

func (*Memory) Start

func (m *Memory) Start()

Start runs the writer until Stop.

func (*Memory) Stop

func (m *Memory) Stop()

Stop writes everything already queued and stops the writer. Writes queued after it are dropped.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL