Add audio list
This commit is contained in:
@@ -36,7 +36,9 @@ type ScrollerPage struct {
|
||||
// legacy Selected-AudioFile track, or nothing yet).
|
||||
currentAudioFreq int
|
||||
|
||||
IsDownloadingAudio bool
|
||||
audioRetryTimer float32
|
||||
audioStarted bool
|
||||
dynamicAudio bool
|
||||
|
||||
lines *LineDeque
|
||||
lineHeight int32
|
||||
@@ -277,16 +279,21 @@ func (p *ScrollerPage) Init(ctx *PageCtx) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Start audio for the first proclamation in the stream. Falls back to
|
||||
// whatever track is marked Selected in the audio_files table if the
|
||||
// first stream has no frequency (e.g. only the default proclamation is
|
||||
// queued) or its matching file doesn't exist on disk yet.
|
||||
// Read DynamicAudio setting from config.
|
||||
p.dynamicAudio = config.DynamicAudio
|
||||
logger.Info("DynamicAudio mode: %v", p.dynamicAudio)
|
||||
|
||||
// Start audio for the first proclamation in the stream.
|
||||
started := false
|
||||
if len(p.streams) > 0 {
|
||||
started = p.switchAudioForFrequency(p.streams[0].frequencyValue)
|
||||
if p.dynamicAudio {
|
||||
started = p.switchAudioForFrequency(p.streams[0].frequencyValue)
|
||||
}
|
||||
}
|
||||
|
||||
if !started {
|
||||
// Non-dynamic mode or frequency-specific file not yet available.
|
||||
// Play whatever track is marked Selected in the audio_files table.
|
||||
var selectedAudio db.AudioFile
|
||||
if err := p.Context.DbPtr.Where("Selected = ?", true).First(&selectedAudio).Error; err != nil {
|
||||
selectedAudio = db.AudioFile{
|
||||
@@ -303,6 +310,8 @@ func (p *ScrollerPage) Init(ctx *PageCtx) error {
|
||||
}
|
||||
}
|
||||
|
||||
p.audioStarted = started
|
||||
|
||||
currentDevice := mixer.CurrentDevice()
|
||||
if currentDevice == "" {
|
||||
currentDevice = "default"
|
||||
@@ -501,8 +510,11 @@ func (p *ScrollerPage) nextLineWords() []string {
|
||||
s.wordIndex = 0
|
||||
s.colorIndex = 0 // Reset color index when proclamation restarts
|
||||
p.streamIndex = (p.streamIndex + 1) % len(p.streams)
|
||||
next := &p.streams[p.streamIndex]
|
||||
p.switchAudioForFrequency(next.frequencyValue)
|
||||
if p.dynamicAudio {
|
||||
next := &p.streams[p.streamIndex]
|
||||
result := p.switchAudioForFrequency(next.frequencyValue)
|
||||
p.audioStarted = result || next.frequencyValue == 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -633,6 +645,20 @@ func (p *ScrollerPage) HandleEvent(event *sdl.Event) error {
|
||||
func (p *ScrollerPage) Update(dt float32) error {
|
||||
p.updateAutoVelocity(dt)
|
||||
|
||||
// In dynamic mode, retry audio switch every 5 seconds until the
|
||||
// frequency-specific file is found. In non-dynamic mode the selected
|
||||
// file plays continuously — nothing to retry.
|
||||
if p.dynamicAudio && !p.audioStarted {
|
||||
p.audioRetryTimer += dt
|
||||
if p.audioRetryTimer >= 5.0 {
|
||||
p.audioRetryTimer = 0
|
||||
if len(p.streams) > 0 {
|
||||
freq := p.streams[p.streamIndex].frequencyValue
|
||||
p.audioStarted = p.switchAudioForFrequency(freq) || freq == 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
p.scrollOffset += dt * p.velocity
|
||||
move := int32(p.scrollOffset)
|
||||
if move == 0 {
|
||||
|
||||
Reference in New Issue
Block a user