use servefile for streaming

This commit is contained in:
sentriz
2019-08-01 13:57:16 +01:00
parent 0b929bd326
commit c75732868d
4 changed files with 9 additions and 8 deletions

View File

@@ -2,7 +2,6 @@ package ctrlsubsonic
import (
"net/http"
"os"
"path"
"time"
@@ -65,12 +64,7 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R
track.Album.RightPath,
track.Filename,
)
file, err := os.Open(absPath)
if err != nil {
return spec.NewError(0, "error while streaming media: %v", err)
}
stat, _ := file.Stat()
http.ServeContent(w, r, absPath, stat.ModTime(), file)
http.ServeFile(w, r, absPath)
//
// after we've served the file, mark the album as played
user := r.Context().Value(key.User).(*model.User)