2012-03-30 3 views
1

사용자가 iPad (Safari 브라우저)에서 파일을 볼 수있는 웹 응용 프로그램을 개발 중입니다. .pdf, .doc, .ppt 파일을 다운로드하고 볼 수 있습니다. 하지만 MP4 및 3GP 파일을 다운로드하고 볼 수 없습니다. IIS에 올바른 MIME 형식을 추가했습니다. Safari (iPad)에서 'BYTE_RANGE_ERROR_MESSAGE'오류가 발생합니다. Windows Server 2008에서 IIS 7.0을 사용 중입니다.iPad에서 mp4/3gp 파일을 다운로드 할 수 없습니다.

참고 : IE, Mozilla 및 Safari를 사용하여 PC의 모든 파일을 다운로드 할 수 있습니다.

답변

1

아래의 샘플 코드는 asp.net 처리기를 통해 mp4 비디오를 스트리밍하는 데 도움이됩니다. processRequest 메소드에서 기능의

private void RangeDownload(string fullpath,HttpContext context) 
{ 
    long size,start,end,length,fp=0; 
    using (StreamReader reader = new StreamReader(fullpath)) 
    {    
     size = reader.BaseStream.Length;  
     start = 0; 
     end = size - 1; 
     length = size; 
     context.Response.AddHeader("Accept-Ranges", "0-" + size); 

     if (!String.IsNullOrEmpty(context.Request.ServerVariables["HTTP_RANGE"])) 
     { 
      long anotherStart = start; 
       long anotherEnd = end; 
       string[] arr_split = context.Request.ServerVariables["HTTP_RANGE"].Split(new char[] { Convert.ToChar("=") }); 
       string range = arr_split[1]; 

      // Make sure the client hasn't sent us a multibyte range 
      if (range.IndexOf(",") > -1) 
      {      
        context.Response.AddHeader("Content-Range", "bytes " + start + "-" + end + "/" + size); 
        throw new HttpException(416, "Requested Range Not Satisfiable"); 

       } 


       if (range.StartsWith("-")) 
       { 
        // The n-number of the last bytes is requested 
        anotherStart = size - Convert.ToInt64(range.Substring(1)); 
       } 
       else 
       { 
        arr_split = range.Split(new char[] { Convert.ToChar("-") }); 
        anotherStart = Convert.ToInt64(arr_split[0]); 
       long temp = 0; 
        anotherEnd = (arr_split.Length > 1 && Int64.TryParse(arr_split[1].ToString(), out temp)) ? Convert.ToInt64(arr_split[1]) : size; 
       } 

       anotherEnd = (anotherEnd > end) ? end : anotherEnd; 

       if (anotherStart > anotherEnd || anotherStart > size - 1 || anotherEnd >= size) 
       { 

        context.Response.AddHeader("Content-Range", "bytes " + start + "-" + end + "/" + size); 
       throw new HttpException(416, "Requested Range Not Satisfiable"); 
      } 
      start = anotherStart; 
       end = anotherEnd; 

       length = end - start + 1; // Calculate new content length 
      fp = reader.BaseStream.Seek(start, SeekOrigin.Begin); 
      context.Response.StatusCode = 206; 
      } 
    } 
      // Notify the client the byte range we'll be outputting 
     context.Response.AddHeader("Content-Range", "bytes " + start + "-" + end + "/" + size); 
     context.Response.AddHeader("Content-Length", length.ToString()); 
     // Start buffered download 
      context.Response.WriteFile(fullpath, fp, length); 
      context.Response.End(); 

} 

샘플 사용이 코드는 당신을 도울 것입니다

string mimetype = "video/mp4"; 
if (System.IO.File.Exists(file)) 
{ 
    context.Response.ContentType = mimetype; 
    if (!String.IsNullOrEmpty(context.Request.ServerVariables["HTTP_RANGE"])) 
    { 
     //request for chunk 
     RangeDownload(file, context); 
    } 
    else  
    { 
     //ask for all 
     long fileLength = File.OpenRead(file).Length; 
     context.Response.AddHeader("Content-Length", fileLength.ToString()); 
     context.Response.WriteFile(file); 
    } 
} 
else 
{ 
    throw new HttpException(404, "Video Not Found Path:" + file); 
} 

희망.

+0

덕분에 내 문제가 해결되었습니다. –

관련 문제