简体   繁体   中英

iOS and byte range video streaming not working

Currently have a bit of a situation where iOS (10.2.1) doesn't want to request a video with a byte range in the HTML video element - it wants to download the entire video before it starts to play. Naturally this is ridiculous for a large video file, and on a 4G connection - has anyone had this problem?

Using Web API 2 to stream the content -

            string mapped = HostingEnvironment.MapPath(vmApplication.Instance.VideoPath);
            string filename = Path.Combine(mapped, name);
            string ext = System.IO.Path.GetExtension(filename)?.ToLower().Trim('.');
            string contentType = MimeMapping.GetMimeMapping(filename);
            switch (ext)
            {
                case "webm": contentType = "video/webm"; break;
                case "mp4": contentType = "video/mp4"; break;
                case "ogg": contentType = "video/ogg"; break;
            }
            MediaTypeHeaderValue _mediaType = MediaTypeHeaderValue.Parse(contentType);


            FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
            if (Request.Headers.Range == null)
            {
                Request.Headers.Range = new RangeHeaderValue(0, null);
            }
            try
            {

                HttpResponseMessage partialResponse = Request.CreateResponse(HttpStatusCode.PartialContent);
                ByteRangeStreamContent content = new ByteRangeStreamContent(fs, Request.Headers.Range, _mediaType, VIDEOBUFFER);
                partialResponse.Content = content;
                return partialResponse;
            }
            catch (InvalidByteRangeException invalidByteRangeException)
            {
                return Request.CreateErrorResponse(invalidByteRangeException);
            }

The HTML element is pretty basic, using videojs

    <video id="video-1" controls preload="none" data-setup='{ "fluid": true }' poster="@Url.Content("~/Content/images/poster/video-1.jpeg")" class="video-js vjs-default-skin vjs-big-play-centered">
        <source src="@Url.RouteUrl("DefaultApi",new {httproute = "", id = "File", controller = "Video", name = "video-1.webm" })" type='video/webm' />
        <source src="@Url.RouteUrl("DefaultApi",new {httproute = "", id = "File", controller = "Video", name = "video-1.mp4" })" type='video/mp4' />
        <source src="@Url.RouteUrl("DefaultApi",new {httproute = "", id = "File", controller = "Video", name = "video-1.ogg" })" type='video/ogg' />
        <p class="vjs-no-js">
            To view this video please enable JavaScript, and consider upgrading to a web browser that
            <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
        </p>
    </video>

No luck at all with this, any help would be greatly appreciated

FFmpeg has an option (-movflags +faststart) to pre-render the video file and play it while loading. Check if your converter has a similar option.

You can try preload="auto" or preload="metadata"

Also, check if http request AND response headers contains the Range parameter. If request does and response do not it means a bad IIS setting on Byte-Range.

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM