iOS视频范围无法正常工作 [英] iOS video range not working

查看:89
本文介绍了iOS视频范围无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有html5视频播放器的.NET网页。视频源是一个返回部分范围请求的类。它适用于桌面浏览器和Android,但它不适用于iOS设备。



我尝试过:



I have a .NET web page with a html5 video player on in. The source of the video is a class that return partial range request. It works in desktop browsers and android, but it doesn't work on iOS devices.

What I have tried:

Private Sub RangeDownload(fullpath As String, context As HttpContext)

        Dim size As Long
        Dim start As Long
        Dim theend As Long
        Dim length As Long
        Dim fp As Long = 0
        Using reader As New System.IO.StreamReader(fullpath)
            size = reader.BaseStream.Length
            start = 0
            theend = size - 1
            length = size
            '/ Now that we've gotten so far without errors we send the accept range header
            '* At the moment we only support single ranges.
            '* Multiple ranges requires some more work to ensure it works correctly
            '* and comply with the spesifications: http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2
            '*
            '* Multirange support annouces itself with:
            '* header('Accept-Ranges: bytes');
            '*
            '* Multirange content must be sent with multipart/byteranges mediatype,
            '* (mediatype = mimetype)
            '* as well as a boundry header to indicate the various chunks of data.
            '*/
            context.Response.AddHeader("Accept-Ranges", "0-" + size)
            '// header('Accept-Ranges: bytes')
            '// multipart/byteranges
            '// http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2

            If (Not String.IsNullOrEmpty(context.Request.ServerVariables("HTTP_RANGE"))) Then
                Dim anotherStart As Long = start
                Dim anotherEnd As Long = theend
                Dim arr_split As String() = context.Request.ServerVariables("HTTP_RANGE").Split("=") 'new char[] { Convert.ToChar("=") })
                Dim range As String = arr_split(1)

                '// Make sure the client hasn't sent us a multibyte range
                If (range.IndexOf(",") > -1) Then
                    '// (?) Shoud this be issued here, or should the first
                    '// range be used? Or should the header be ignored and
                    '// we output the whole content?
                    context.Response.AddHeader("Content-Range", "bytes " & start & "-" & theend & "/" & size)
                    Throw New HttpException(416, "Requested Range Not Satisfiable")
                End If

                '// If the range starts with an '-' we start from the beginning
                '// If not, we forward the file pointer
                '// And make sure to get the end byte if spesified
                If (range.StartsWith("-")) Then
                    '// The n-number of the last bytes is requested
                    anotherStart = size - Convert.ToInt64(range.Substring(1))
                Else
                    arr_split = range.Split("-")
                    anotherStart = Convert.ToInt64(arr_split(0))
                    Dim temp As Long = 0
                    If (arr_split.Length > 1 AndAlso Int64.TryParse(arr_split(1).ToString(), temp)) Then
                        anotherEnd = Convert.ToInt64(arr_split(1))
                    Else
                        anotherEnd = size
                    End If
                End If
                '/* Check the range and make sure it's treated according to the specs.
                ' * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
                ' */
                '// End bytes can not be larger than $end.
                If (anotherEnd > theend) Then
                    anotherEnd = theend
                Else
                    anotherEnd = anotherEnd
                End If
                '// Validate the requested range and return an error if it's not correct.
                If (anotherStart > anotherEnd Or anotherStart > size - 1 Or anotherEnd >= size) Then
                    context.Response.AddHeader("Content-Range", "bytes " + start + "-" + theend + "/" + size)
                    Throw New HttpException(416, "Requested Range Not Satisfiable")
                End If

                start = anotherStart
                theend = anotherEnd

                length = theend - start + 1 '// Calculate new content length
                fp = reader.BaseStream.Seek(start, System.IO.SeekOrigin.Begin)
                context.Response.StatusCode = 206
            End If
        End Using

        '// Notify the client the byte range we'll be outputting
        context.Response.AddHeader("Content-Range", "bytes " & start & "-" & theend & "/" & size)
        context.Response.AddHeader("Content-Length", length.ToString())
        '// Start buffered download
        context.Response.WriteFile(fullpath, fp, length)
        context.Response.End()
    End Sub

推荐答案

end。
如果(anotherEnd> theend)那么
anotherEnd = theend
Else
anotherEnd = anotherEnd
End if
' // 验证请求的范围,如果不正确,则返回错误。
If(anotherStart > anotherEnd或anotherStart > size - 1 或anotherEnd > = size)然后
context.Response.AddHeader( Content-Range bytes + start + - + theend + / + size)
抛出新的HttpException( 416 Requested范围不满意
结束如果

start = anotherStart
theend = anotherEnd

length = theend - start + 1 ' //计算新的内容长度
fp = reader .BaseStream.Seek(start,System.IO.SeekOrigin.Begin)
context.Response.StatusCode = 206
End if
End using

'
// 通知客户端我们将输出的字节范围
context.Response。 AddHeader( Content-Range 字节&开始& - & theend& /& size)
context.Response.AddHeader( Content-Length,length.ToString( ))
' //开始缓冲下载
context.Response.WriteFile(fullpath,fp,长度)
context.Response.End()
End Sub
end. If (anotherEnd > theend) Then anotherEnd = theend Else anotherEnd = anotherEnd End If '// Validate the requested range and return an error if it's not correct. If (anotherStart > anotherEnd Or anotherStart > size - 1 Or anotherEnd >= size) Then context.Response.AddHeader("Content-Range", "bytes " + start + "-" + theend + "/" + size) Throw New HttpException(416, "Requested Range Not Satisfiable") End If start = anotherStart theend = anotherEnd length = theend - start + 1 '// Calculate new content length fp = reader.BaseStream.Seek(start, System.IO.SeekOrigin.Begin) context.Response.StatusCode = 206 End If End Using '// Notify the client the byte range we'll be outputting context.Response.AddHeader("Content-Range", "bytes " & start & "-" & theend & "/" & size) context.Response.AddHeader("Content-Length", length.ToString()) '// Start buffered download context.Response.WriteFile(fullpath, fp, length) context.Response.End() End Sub


这篇关于iOS视频范围无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆