Hack to make streaming work, but with wrong content-length

This commit is contained in:
Deluan 2016-03-10 11:14:47 -05:00
parent 972d1c04bc
commit 42f3279aaf
2 changed files with 13 additions and 9 deletions

View file

@ -1,8 +1,6 @@
package api
import (
"strconv"
"github.com/astaxie/beego"
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/domain"
@ -46,16 +44,22 @@ func (c *StreamController) Stream() {
beego.Debug("Streaming file", c.id, ":", c.mf.Path)
beego.Debug("Bitrate", c.mf.BitRate, "MaxBitRate", maxBitRate)
contentLength := c.mf.Size
if maxBitRate > 0 {
contentLength = strconv.Itoa((c.mf.Duration + 1) * maxBitRate * 1000 / 8)
}
c.Ctx.Output.Header("Content-Length", contentLength)
// TODO Send proper estimated content-length
//contentLength := c.mf.Size
//if maxBitRate > 0 {
// contentLength = strconv.Itoa((c.mf.Duration + 1) * maxBitRate * 1000 / 8)
//}
c.Ctx.Output.Header("Content-Length", c.mf.Size)
c.Ctx.Output.Header("Content-Type", "audio/mpeg")
c.Ctx.Output.Header("Expires", "0")
c.Ctx.Output.Header("Cache-Control", "must-revalidate")
c.Ctx.Output.Header("Pragma", "public")
if c.Ctx.Request.Method == "HEAD" {
beego.Debug("Just a HEAD. Not streaming", c.mf.Path)
return
}
err := engine.Stream(c.mf.Path, c.mf.BitRate, maxBitRate, c.Ctx.ResponseWriter)
if err != nil {
beego.Error("Error streaming file", c.id, ":", err)

View file

@ -20,8 +20,8 @@ plsIgnoreFolders = true
plsIgnoredPatterns = ^iCloud;^CDs para;^Skipped;Christian
[dev]
disableValidation = false
enableDownsampling = false
disableValidation = true
enableDownsampling = true
enableAdmin = true
[test]