Skip to content

Commit 86555f1

Browse files
committed
live stream metadata
1 parent ab9d5d4 commit 86555f1

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ func icecastNormalizerFeeder() {
2525
// Transition: Source connected, start Icecast mode
2626
if hasSource && !isIcecastProcessing {
2727
modules.Logger.Info("Icecast source connected - switching to Icecast mode")
28+
29+
// Close current file and advance to next song before switching modes
30+
// This ensures: 1) current file is released (no lock for cleanup), 2) next song is ready when Icecast disconnects
31+
modules.MusicReader.SkipToNext()
32+
modules.Logger.Info("Advancing to next song in preparation for Icecast mode")
33+
2834
modules.MusicReader.EnableIcecastMode()
2935

3036
// Create a channel to signal when processor is done

routes/fm.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,18 @@ func GetFMStream(ctx echo.Context) error {
126126
// Check if we haven't received data for too long
127127
// Send heartbeat metadata to keep connection alive
128128
if wantMetadata && time.Since(lastBufferUpdateTime) > maxNoDataTimeout {
129-
musicInfo := modules.MusicReader.GetMusicInfo()
130-
if musicInfo != nil && musicInfo.Filename != "" {
131-
metadata := BuildIcecastMetadata(musicInfo.Filename, musicInfo.Url)
129+
var metadata []byte
130+
if modules.MusicReader.IsIcecastMode {
131+
// Live streaming mode - send generic live metadata
132+
metadata = BuildIcecastMetadata("Live Stream", modules.Config.URL)
133+
} else {
134+
// File mode - send current song metadata
135+
musicInfo := modules.MusicReader.GetMusicInfo()
136+
if musicInfo != nil && musicInfo.Filename != "" {
137+
metadata = BuildIcecastMetadata(musicInfo.Filename, musicInfo.Url)
138+
}
139+
}
140+
if len(metadata) > 0 {
132141
_, err := res.Write(metadata)
133142
if err != nil {
134143
modules.Logger.Info(fmt.Sprintf("[%s] Client %s disconnected", requestID, ip))
@@ -193,9 +202,18 @@ func GetFMStream(ctx echo.Context) error {
193202

194203
// If we hit metadata boundary, inject metadata
195204
if sinceMetaBlock >= metaintInterval && offset < bufLen {
196-
musicInfo := modules.MusicReader.GetMusicInfo()
197-
if musicInfo != nil && musicInfo.Filename != "" {
198-
metadata := BuildIcecastMetadata(musicInfo.Filename, musicInfo.Url)
205+
var metadata []byte
206+
if modules.MusicReader.IsIcecastMode {
207+
// Live streaming mode - send generic live metadata
208+
metadata = BuildIcecastMetadata("Live Stream", modules.Config.URL)
209+
} else {
210+
// File mode - send current song metadata
211+
musicInfo := modules.MusicReader.GetMusicInfo()
212+
if musicInfo != nil && musicInfo.Filename != "" {
213+
metadata = BuildIcecastMetadata(musicInfo.Filename, musicInfo.Url)
214+
}
215+
}
216+
if len(metadata) > 0 {
199217
_, err := res.Write(metadata)
200218
if err != nil {
201219
modules.Logger.Info(fmt.Sprintf("[%s] Client %s disconnected", requestID, ip))

0 commit comments

Comments
 (0)