无法从iframe实时运行流

时间:2016-06-11 11:22:10

标签: c# asp.net iframe

我使用 iframe 在asp.net中运行直播。但事实是,我正在尝试从实时视频中捕捉屏幕截图。但问题是,它只是从头开始捕获。

我正在关注herehere的教程和示例。 但我不知道我缺少的地方。

这是网页上的输出屏幕: enter image description here

按下播放按钮后: 我的流媒体就是这样开始的:

enter image description here

但是当我按下捕获时它会显示:

enter image description here

当我在实时视频播放时按下捕获按钮时,我希望捕获完全相同的帧截图。

这是我的代码:

screen2.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

</head>
<body>
<form id="form1" runat="server">
    <asp:TextBox ID="txtUrl" runat="server" Text="" />
    <iframe id="iframeDemo" runat="server" src="http://videoplayer.vodobox.com/vodobox_player.php?vid=http%3A%2F%2Fs69362.cdn.ngenix.net%2Flive%2F_definst_%2FStream1%2Fchunklist.m3u8&img=&play=1" height="500px"
        width="500px"></iframe>
    <asp:ScriptManager ID="MainScriptManager" runat="server" />
        <asp:UpdatePanel ID="pnlHelloWorld" runat="server">
            <ContentTemplate>
                <asp:Button Text="Capture" runat="server" OnClick="Capture" />
                <br />
                <asp:Image ID="imgScreenShot" runat="server" Height="500" Width="700" Visible="false" />

            </ContentTemplate>
        </asp:UpdatePanel>
 </form>
</body>
</html>

代码背后: screen2.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.IO;
using System.Threading;
using System.Windows.Forms;


namespace screenshot2
{
    public partial class screen2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Capture(object sender, EventArgs e)
        {
            //string url = txtUrl.Text.Trim();
            string url = this.iframeDemo.Attributes["src"].ToString();
            Thread thread = new Thread(delegate ()
            {
                using (WebBrowser browser = new WebBrowser())
                {
                    browser.ScrollBarsEnabled = false;
                    browser.AllowNavigation = true;
                    browser.Navigate(url);
                    browser.Width = 1024;
                    browser.Height = 768;
                    browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(DocumentCompleted);
                    while (browser.ReadyState != WebBrowserReadyState.Complete)
                    {
                        System.Windows.Forms.Application.DoEvents();
                    }
                }
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
        }

        private void DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            WebBrowser browser = sender as WebBrowser;
            using (Bitmap bitmap = new Bitmap(browser.Width, browser.Height))
            {
                browser.DrawToBitmap(bitmap, new Rectangle(0, 0, browser.Width, browser.Height));
                using (MemoryStream stream = new MemoryStream())
                {
                    bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                    byte[] bytes = stream.ToArray();
                    imgScreenShot.Visible = true;
                    imgScreenShot.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(bytes);
                }
            }
        }

    }
}

任何想法。请帮忙。

0 个答案:

没有答案