lord_wilmore
lord_wilmore

Reputation: 31

Seeking not working in HTML5 audio tag

I have a lighttpd server running locally. If I load a static file on the server (through an html5 audio tag), it plays and seeks fine.

However, seeking doesn't work when running a dev server (web.py/CherryPy) or if I return the bytes via a defined action url instead of as a static file. It won't load the duration either.

According to the "HTTP byte range requests" section in this Opera Page it's something to do with support for byte range requests/partial content responses. The content is treated as streaming instead.

What I don't understand is:

Any advice would be most gratefully received.

Upvotes: 3

Views: 2498

Answers (2)

Ivo van der Wijk
Ivo van der Wijk

Reputation: 16785

Here's some web.py code to get you started (just happened to need this as well and ran into your question):

## experimental partial content support
## perhaps this shouldn't be enabled by default
range = web.ctx.env.get('HTTP_RANGE')
if range is None:
    return result

total = len(result)
_, r = range.split("=")
partial_start, partial_end = r.split("-")

start = int(partial_start)

if not partial_end:
    end = total-1
else:
    end = int(partial_end)

chunksize = (end-start)+1

web.ctx.status = "206 Partial Content"
web.header("Content-Range", "bytes %d-%d/%d" % (start, end, total))
web.header("Accept-Ranges", "bytes")
web.header("Content-Length", chunksize)
return result[start:end+1] 

Upvotes: 1

Simon Groenewolt
Simon Groenewolt

Reputation: 10665

Google tells me you have to use the staticFilter for byte ranges to work in CherryPy - but that is for static files only. Luckily this posting also includes pointers on how to do it for non-static data :-)

Upvotes: 0

Related Questions