从Webapi流播放WindowsForm WindowsMediaPlayer

时间:2019-03-15 11:18:41

标签: c# winforms video-streaming axwindowsmediaplayer

我有一个简单的webapi用于返回视频,如this answer所述。

代码

    [HttpGet]
    [Route("api/v1/video-stream/template/{TemplateFileName}/")]
    public HttpResponseMessage InitializeApplication([FromUri] string TemplateFileName)
    {
        string path = Path.Combine(root, System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(TemplateFileName)));
        byte[] _content = File.ReadAllBytes(path);
        using (MemoryStream stream = new MemoryStream(_content))
        {
            if (Request.Headers.Range != null)
            {
                // Return part of the video
                HttpResponseMessage partialResponse = Request.CreateResponse(HttpStatusCode.PartialContent);
                partialResponse.Content = new ByteRangeStreamContent(stream, Request.Headers.Range, MediaTypeHeaderValue.Parse("video/mp4"));
                return partialResponse;
            }
            else
            {
                // Return complete video
                HttpResponseMessage fullResponse = Request.CreateResponse(HttpStatusCode.OK);
                fullResponse.Content = new StreamContent(stream);
                fullResponse.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("video/mp4");
                return fullResponse;
            }
        }
    }

我正在尝试在WinForm application中播放此api流式传输的视频,而我正在尝试执行以下操作:

    private void btnPlay_Click(object sender, EventArgs e)
    {
        player.URL = $"http://mywebapi/api/v1/video-stream/template/{Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("TEST.mp4"))}";
        player.Ctlcontrols.play();
    }

成功调用了我的webapi,但是我的播放器出现错误:

  

-1072885782(或使用ToString("X"),C00D0FEA)

由于我从未使用过这两种方法,所以我肯定会丢失一些东西,但是关于如何使其起作用的任何想法吗?

谢谢

0 个答案:

没有答案