I'm building a simple app that requires me to use the webview option

I’m building a simple app that requires me to use the webview option

    local physics = require( “physics” )
    local composer = require ( “composer” )
    Create a composer scene for this module
    local scene = composer.newScene()
    function scene:create( event )
    local sceneLanding = self.view
    
    
    local soundID = audio.loadSound (“gummy_music.wav”)

    local webView = native.newWebView( display.contentCenterX, display.contentCenterY, 320, 480 )
    webView:request( “page.html”, system.ResourceDirectory )
    webView:addEventListener( “urlRequest”, webListener )

The page pulls up and renders fine

I’m trying to figure out how to use the listener function in coronasdk to play a sound when an event occurs in the local html file.

something like this in my page.lua ?

    local function webListener( event )
    audio.play( soundID )
    end

I’m looking for a way using jquery to hit the webListener to play the audio.
 

I haven’t tested this but it could be possible.

Try to communicate to JavaScript using injection:

[lua]webView:request(“javascipt: alert(‘hello’);”)[/lua]

And for the communication in other direction try to use links in you HTML, and a listener for your webview.

[lua]local function webListener( event )

    if event.url then

        print( "You are visiting: " … event.url )

    end

    if event.type then

        print( "The event.type is " … event.type  – print the type of request

    end

    if event.errorCode then

        native.showAlert( “Error!”, event.errorMessage, { “OK” } )

    end

end

local webView = native.newWebView( 0, 0, 320, 480, webListener )

webView:request( “http://www.anscamobile.com/” )

webView:addEventListener( “urlRequest”, webListener )[/lua]

That way you could catch a URL loading event. Let me know if that works.

Daniel

Thanks Daniel, but I’m still lost

I haven’t tested this but it could be possible.

Try to communicate to JavaScript using injection:

[lua]webView:request(“javascipt: alert(‘hello’);”)[/lua]

And for the communication in other direction try to use links in you HTML, and a listener for your webview.

[lua]local function webListener( event )

    if event.url then

        print( "You are visiting: " … event.url )

    end

    if event.type then

        print( "The event.type is " … event.type  – print the type of request

    end

    if event.errorCode then

        native.showAlert( “Error!”, event.errorMessage, { “OK” } )

    end

end

local webView = native.newWebView( 0, 0, 320, 480, webListener )

webView:request( “http://www.anscamobile.com/” )

webView:addEventListener( “urlRequest”, webListener )[/lua]

That way you could catch a URL loading event. Let me know if that works.

Daniel

Thanks Daniel, but I’m still lost