Skip to content

🎧 Your Personal Streaming Service

feat: add X-Content-Duration header to the stream response

Deluana37beac753cd
diff --git a/engine/media_streamer.go b/engine/media_streamer.go
index 70f7ac846..2919617f1 100644
--- a/engine/media_streamer.go
+++ b/engine/media_streamer.go
@@ -31,6 +31,7 @@ type mediaStream interface {
Name() string
ModTime() time.Time
Close() error
+ Duration() int
}
type mediaStreamer struct {
@@ -108,6 +109,10 @@ func (m *rawMediaStream) ModTime() time.Time {
return m.mf.UpdatedAt
}
+func (m *rawMediaStream) Duration() int {
+ return m.mf.Duration
+}
+
func (m *rawMediaStream) Close() error {
log.Trace(m.ctx, "Closing file", "id", m.mf.ID, "path", m.mf.Path)
return m.file.Close()
@@ -186,6 +191,10 @@ func (m *transcodedMediaStream) ModTime() time.Time {
return m.mf.UpdatedAt
}
+func (m *transcodedMediaStream) Duration() int {
+ return m.mf.Duration
+}
+
func (m *transcodedMediaStream) Close() error {
log.Trace(m.ctx, "Closing stream", "id", m.mf.ID, "path", m.mf.Path)
err := m.pipe.Close()
diff --git a/server/subsonic/stream.go b/server/subsonic/stream.go
index 7837b7e12..5f93e50cb 100644
--- a/server/subsonic/stream.go
+++ b/server/subsonic/stream.go
@@ -2,6 +2,7 @@ package subsonic
import (
"net/http"
+ "strconv"
"github.com/deluan/navidrome/engine"
"github.com/deluan/navidrome/server/subsonic/responses"
@@ -31,6 +32,7 @@ func (c *StreamController) Stream(w http.ResponseWriter, r *http.Request) (*resp
// Override Content-Type detected by http.FileServer
w.Header().Set("Content-Type", ms.ContentType())
+ w.Header().Set("X-Content-Duration", strconv.Itoa(ms.Duration()))
http.ServeContent(w, r, ms.Name(), ms.ModTime(), ms)
return nil, nil
}