Local or streamed audio using JavaScript with CefSharp or CefGlue

I've been toying with CefSharp and CefGlue and managed to get CefSharp to work quite well in a C# application.

With CefSharp, I am able to execute JavaScript and load HTML from memory. For example, to execute some JavaScript, one can do this:

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

To load some HTML:

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

I know I can load <audio> with some file loaded from some web server. Is there a way to load audio either from a local file or through a stream with CefGlue/Sharp?

Even better, how can this be done with "dynamic" JavaScript (for example by using ExecuteScript(...) above)?

Answers


I've figured it out. It's done by impersonating a web server. The difficulty appears to be the interpretation of what is requested, which seems to be done by parsing the requested URL. Otherwise it all works great.

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;
}

Need Your Help

How do I print all current Play2 configs?

scala playframework playframework-2.2 typesafe-stack typesafe-config

I have val config = Play.current.configuration and I want to get a Map[String, String] of all current configs key and their string values. How can I do that?

Annotation title cannot be shown after change the pincolor

ios annotations mkmapview mkpinannotationview

I used this code to change the annotation's color,but after that,the title and subtitle can not be showed,how can I save this problem?