【问题标题】:Local or streamed audio using JavaScript with CefSharp or CefGlue使用带有 CefSharp 或 CefGlue 的 JavaScript 的本地或流式音频
【发布时间】:2012-09-08 16:08:35
【问题描述】:

我一直在玩弄 CefSharpCefGlue 并设法让 CefSharp 在 C# 应用程序中运行良好。

使用 CefSharp,我能够执行 JavaScript 并从内存中加载 HTML。例如,要执行一些 JavaScript,可以这样做:

view.ExecuteScript("setInterval(function(){alert(\"Hello\")},3000);");

加载一些 HTML:

model.LoadHtml(string.Format("<html><body><a href='{0}'>CefSharp Home</a></body></html>", home_url));

我知道我可以加载 &lt;audio&gt; 并从某个 Web 服务器加载一些文件。有没有办法从本地文件或通过 CefGlue/Sharp 的流加载音频?

更好的是,如何使用“动态”JavaScript(例如使用上面的ExecuteScript(...))来做到这一点?

【问题讨论】:

    标签: c# javascript html audio chromium


    【解决方案1】:

    我想通了。它是通过模拟 Web 服务器来完成的。困难似乎在于对所请求内容的解释,这似乎是通过解析请求的 URL 来完成的。否则一切都很好。

    public bool OnBeforeResourceLoad(IWebBrowser browser, 
        IRequestResponse requestResponse)
    {
        IRequest request = requestResponse.Request;
    
        if (request.Url.EndsWith(".gif")) {
            MemoryStream stream = new System.IO.MemoryStream();
            Properties.Resources.FooImage.Save(
                stream, System.Drawing.Imaging.ImageFormat.Bmp);
            requestResponse.RespondWith(stream, "image/gif");
        }
        else {
    
            Stream resourceStream = new MemoryStream(Encoding.UTF8.GetBytes(
                "<html><body><img src=\"foo.gif\" /></body></html>"));
            requestResponse.RespondWith(resourceStream, "text/html");
        }
    
        return false;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-05
      • 2020-03-09
      • 1970-01-01
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-14
      相关资源
      最近更新 更多