android media player - how to disable range request? (broken audio streaming on Nexus 7)

前端 未结 3 1643
轮回少年
轮回少年 2021-01-30 06:03

I have a audio streaming app, which runs a local proxy server. The local proxy server makes a http connection to a internet streaming source, gets and buffers locally the stream

3条回答
  •  感情败类
    2021-01-30 06:22

    We've finally solved this in a clean way. In our case we have full control over the streaming server, but i guess you could do this with a local proxy as well. Since Build.VERSION_CODES.ICE_CREAM_SANDWICH it's possible to set headers for the MediaPlayer object. As our app enables the user to seek inside the audio stream, we've implemented this Range header on the client. If the server responds with the proper headers, the MediaPlayer will not try multimple times to request the stream.

    That's what our server headers look like now for the android client:

    Content-Type: audio/mpeg
    Accept-Ranges: bytes
    Content-Length: XXXX
    Content-Range: bytes XXX-XXX/XXX
    Status: 206
    

    The important part is the 206 status code (partial content). If you don't send this header, the android client will try to re-request the source, no matter what.

    If your player doesn't allow seeking in the stream, you could simply always set the Range header to 0-some arbitrary large number.

提交回复
热议问题