1

I've seen numerous questions with people having troubles with implementing video streaming for iOS and Safari. I have tried implementing all of the common pitfalls that I have read about in other questions, but I have not been successful.

I am trying to stream a video from an ASP NET Core 3.1 controller. This works completely correctly in basically every browser, except on iOS and Safari, for which the video just doesn't load (the player just shows a timebar with length 0:00).

I have shown the controller action and the view that I am using to stream the video below. As you can see, I have added EnableRangeProcessing, set the content length and added the playsinline attribute, which are all the main issues people talk about with iOS and Safari.

Can anyone see any other potential problem here?

public async Task<ActionResult> StreamVideo(int id)
{
    var range = HttpContext.Request.GetTypedHeaders()?.Range?.Ranges.FirstOrDefault();
    Stream data = await _service.DownloadVideo(id);

    if (range is null) Response.ContentLength = data.Length;
    else 
    {
        Response.ContentLength = (range.To.HasValue ? range.To.Value  + 1 : data.Length) - (range.From ?? 0);
    }

    return new FileStreamResult(data, "video/mp4") { EnableRangeProcessing = true };
}
<video style="max-height:100%; max-width: 100%;" controls="controls" preload="auto" playsinline>
  <source src="@Url.Action("StreamVideo", "Attachment", new { Id = id })" type="video/mp4">
</video>
Sam Walpole
  • 1,116
  • 11
  • 26
  • Hi @SamWalpole, Can you tell us the Asp.net core MVC application version and the test environments (IOS and Safari version), it is helpful for us to reproduce the problem? Besides, I also found some similar threads, you could check them: [How to stream a video or a file considering request and response range headers?](https://stackoverflow.com/questions/34047247/) and [Video File streaming not working on Safari/ iOS device in asp.NET Core 2.0](https://stackoverflow.com/questions/51632656/video-file-streaming-not-working-on-safari-ios-device-in-asp-net-core-2-0). – Zhi Lv Jan 19 '21 at 02:22
  • @SamWalpole did you ever manage to figure this out? We're having the same issue. – Kyle Whittington Mar 20 '23 at 16:55

0 Answers0