C# 使用JavaScript和CefSharp或CefGlue的本地或流式音频

C# 使用JavaScript和CefSharp或CefGlue的本地或流式音频,c#,javascript,html,audio,chromium,C#,Javascript,Html,Audio,Chromium,我一直在玩弄并设法让CefSharp在C#应用程序中运行得相当好 使用CefSharp,我能够执行JavaScript并从内存加载HTML。例如,要执行某些JavaScript,可以执行以下操作: view.ExecuteScript("setInterval(function(){alert(\"Hello\")},3000);"); 要加载一些HTML: model.LoadHtml(string.Format("<html><body><a href='{0

我一直在玩弄并设法让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));
model.LoadHtml(string.Format(“,home\uURL));
我知道我可以从某个web服务器加载一些文件来加载
。有没有办法从本地文件或使用CefGlue/Sharp通过流加载音频


更好的是,如何使用“动态”JavaScript实现这一点(例如,使用上面的
ExecuteScript(…)
),我已经找到了答案。这是通过模拟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;
}
public bool OnBeforeResourceLoad(IWebBrowser,
IRequestResponse请求响应)
{
IRequest request=requestResponse.request;
if(request.Url.EndsWith(“.gif”)){
MemoryStream stream=new System.IO.MemoryStream();
Properties.Resources.FooImage.Save(
流,System.Drawing.Imaging.ImageFormat.Bmp);
RespondWith(流,“image/gif”);
}
否则{
Stream resourceStream=新的MemoryStream(Encoding.UTF8.GetBytes(
""));
RespondWith(resourceStream,“text/html”);
}
返回false;
}