Streaming live video from c# core api not working in safari and iPhone

Viewed 37

I am attempting to stream live video from IP cameras through a .net core 5 web api. to a react and react native front end. The following endpoint works perfectly for android and in chrome/firefox but does not play at all in the safari browser and in the iphone app:

[HttpGet("media")]
    public async Task<IActionResult> GetLiveAsync([FromQuery] MediaRequest mediaRequest)
    {
        try
        {
            

            var contentType = _mediaService.GetContentType(mediaRequest.Format);
            //uses http client to get live stream from camera
            var stream = await _mediaService.GetLiveAsync(mediaRequest);

            
            var result = new FileStreamResult(stream, contentType)
            {
                EnableRangeProcessing = true
            };
            return result;
        }
        catch (Exception ex)
        {
            _logger.LogAppError()(ex.StackTrace);
            return BadRequest(ex.Message);
            //return StatusCode(StatusCodes.Status500InternalServerError);
        }
    }

From researching I found that safari requires the content-range header and possibly the content-length header. I attempted to hard code these headers in to see if I could get anything to return with no luck. I also attempted using a partial content response 206 which I also could not get working. See brute force attempt below:

            Response.ContentLength = (61440-0);
            Response.Headers.Add("Accept-Ranges", "bytes");
            Response.Headers.Add("Content-Range", "bytes 0-500/61440");
            
            //Response.ContentLength = 61440;
            //HttpContext.Response.StatusCode = 206;
            var result = new FileStreamResult(stream, contentType)
            {
                EnableRangeProcessing = true
            };
            return result;

So my question is, is it possible to stream live video to safari and iOS? If you need to pass a byte range in request I assume you need to know the file size but this is live video streaming from a camera. Any help is very appreciated!

0 Answers
Related