ストリーミングビデオに問題があります。/IOSクライアント用ストリーミングビデオに関する問題(ASP.NET WEB API 2で開発されたサーバー)
プライベート非同期無効WriteContentToStream(ストリームのOutputStream、HttpContentコンテンツ、TransportContext transportContext)をストリーミングするための
1) The first method: if (Request.Headers.Range != null) { try { var httpResponce = Request.CreateResponse(); httpResponce.Content = new PushStreamContent((Action) WriteContentToStream);return httpResponce; } catch (Exception ex) { return new HttpResponseMessage(HttpStatusCode.InternalServerError); } } else { return new HttpResponseMessage(HttpStatusCode.RequestedRangeNotSatisfiable); }
/方法 :私は2つの方法をASP.NETのWeb API 2上のサーバーを開発し、実装しました{ string relativeFilePath = "〜/ App_Data/Videos/4.mp4"; try { var filePath = System.Web.Hosting.HostingEnvironment.MapPath(relativeFilePath);
int bufferSize = 1000; byte[] buffer = new byte[bufferSize]; using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { int totalSize = (int)fileStream.Length; while (totalSize > 0) { int count = totalSize > bufferSize ? bufferSize : totalSize; int sizeOfReadedBuffer = fileStream.Read(buffer, 0, count); await outputStream.WriteAsync(buffer, 0, sizeOfReadedBuffer); totalSize -= sizeOfReadedBuffer; } } } catch (HttpException ex) { if (ex.ErrorCode == -2147023667) { return; } } finally { outputStream.Close(); }
}
2)第二の方法:
public HttpResponseMessage Test() { if (Request.Headers.Range != null) { try { string relativeFilePath = "~/App_Data/Videos/4.mp4"; var filePath = System.Web.Hosting.HostingEnvironment.MapPath(relativeFilePath); HttpResponseMessage partialResponse = Request.CreateResponse(HttpStatusCode.PartialContent); partialResponse.Headers.AcceptRanges.Add("bytes"); var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read); partialResponse.Content = new ByteRangeStreamContent(stream, Request.Headers.Range, new MediaTypeHeaderValue("video/mp4")); return partialResponse; } catch (Exception) { return new HttpResponseMessage(HttpStatusCode.InternalServerError); } } else { return new HttpResponseMessage(HttpStatusCode.RequestedRangeNotSatisfiable); } }
これらの方法の両方のWebクライアントとAndroidクライアントに働いたが、IOS-クライアントが」doesnのビデオを表示する。 私は、この問題はビデオのコーデック(Appleが推奨するコーデックを使用しています)またはhttpヘッダーである可能性があります。
お返事ありがとうございます!