काम नहीं कर रहा है मैंने पहले इस तकनीक को http://www.strathweb.com/2013/01/asynchronously-streaming-video-with-asp-net-web-api/ का उपयोग किया है और एसिंक वीडियो स्ट्रीमिंग के लिए बिल्कुल सही काम किया है।एएसपी.Net कोर वेब एपीआई में असिनक वीडियो स्ट्रीमिंग
लेकिन एएसपी.नेट कोर के लिए इस तरह से अपेक्षित काम नहीं कर रहा है।
वीडियो स्ट्रीमिंग वर्ग तक है:
public class VideoStream
{
private readonly string _filename;
public VideoStream(string filename)
{
_filename = filename;
}
public async Task WriteToStream(Stream outputStream, HttpContent content, TransportContext context)
{
try
{
var buffer = new byte[65536];
using (var video = File.Open(_filename, FileMode.Open, FileAccess.Read))
{
var length = (int)video.Length;
var bytesRead = 1;
while (length > 0 && bytesRead > 0)
{
bytesRead = video.Read(buffer, 0, Math.Min(length, buffer.Length));
await outputStream.WriteAsync(buffer, 0, bytesRead);
length -= bytesRead;
}
}
}
catch (Exception)
{ return; }
finally
{
outputStream.Flush();
outputStream.Dispose();
}
}
}
और मैं वीडियो स्ट्रीमिंग अनुरोधों के लिए निम्नलिखित कार्रवाई की है: डिफ़ॉल्ट Asp.Net कोर है निर्मित नहीं है मीडिया द्वारा के बाद से
[HttpGet]
[Route("[action]")]
public IActionResult GetVideo(int id)
{
var fileName = GetVideoFileName(id);
var video = new VideoStream(fileName);
var response = new HttpResponseMessage
{
Content = new PushStreamContent(video.WriteToStream, new MediaTypeHeaderValue("video/mp4"))
};
var objectResult = new ObjectResult(response);
objectResult.ContentTypes.Add(new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("video/mp4"));
return objectResult;
}
वीडियो/एमपी 4 के लिए फॉर्मेटर मैंने निम्नलिखित कस्टम मीडिया फॉर्मेटर
public class VideoOutputFormatter : IOutputFormatter
{
public bool CanWriteResult(OutputFormatterCanWriteContext context)
{
if (context == null)
throw new ArgumentNullException(nameof(context));
return true;
}
public async Task WriteAsync(OutputFormatterWriteContext context)
{
if (context == null)
throw new ArgumentNullException(nameof(context));
var response = context.HttpContext.Response;
response.ContentType = "video/mp4";
How to impelemnt ???
}
}
और एफ को जोड़ा है Startup.cs
services.AddMvc(options =>
{
options.OutputFormatters.Add(new VideoOutputFormatter());
});
यह वास्तव में मेरे कस्टम फॉर्मेटर को कॉल करता है। मुझे नहीं पता कि वीडियो/एमपी 4 के लिए इस कस्टम मीडिया फॉर्मेटर को कैसे कार्यान्वित किया जाए। कोई भी मेरी मदद कर सकता है?
साझा करने के लिए धन्यवाद लेकिन मुझे नेट कोर में पुशस्ट्रीम सामग्री नहीं मिल सका, क्या आपके पास कोई नमूना या कुछ है? दुर्भाग्य से, – Soren
@ सोरेन दुर्भाग्यवश, मुझे कोई समाधान नहीं मिला और nginx जैसे रिवर्स-प्रॉक्सी के माध्यम से बस वीडियो की सेवा समाप्त हो गई। – villecoder