Hi i have problem with html5 player and seeking.
This is my action method:
public IActionResult GetAudio(string url)
{
var file = System.IO.File.ReadAllBytes(url);
long fSize = file.Length;
long startbyte = 0;
long endbyte = fSize - 1;
int statusCode = 200;
var rangeRequest = Request.Headers["Range"].ToString();
if (rangeRequest != "")
{
string[] range = Request.Headers["Range"].ToString().Split(new char[] { '=', '-' });
startbyte = Convert.ToInt64(range[1]);
if (range.Length > 2 && range[2] != "") endbyte = Convert.ToInt64(range[2]);
if (startbyte != 0 || endbyte != fSize - 1 || range.Length > 2 && range[2] == "")
{ statusCode = 206; }
}
long desSize = endbyte - startbyte + 1;
Response.StatusCode = statusCode;
Response.ContentType = "audio/wav";
Response.Headers.Add("Content-Accept", Response.ContentType);
Response.Headers.Add("Content-Length", desSize.ToString());
Response.Headers.Add("Content-Range", string.Format("bytes {0}-{1}/{2}", startbyte, endbyte, fSize));
var stream = new MemoryStream(file, (int)startbyte, (int)desSize);
return File(stream, Response.ContentType);
}
Audio player working properly, but i cant seeking throw file. Progres bar also working properly(moving). When i try to seek audio stop for a while and continue playing with the same moment.
Probably i must add so more Headers right?
Ok, this:
Response.Headers.Add("Accept-Ranges", "bytes");
Response.Headers.Remove("Cache-Control");
Resolved my problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With