监听在corona sdk中触发的localfile.html webview事件

时间:2014-08-09 15:58:19

标签: webview lua listener corona

我正在构建一个简单的应用程序,需要我使用webview选项

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 )

页面拉起并呈现正常

我正在尝试弄清楚如何在coronasdk中使用侦听器函数在本地html文件中发生事件时播放声音。

在我的页面中是这样的.lua?

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

我正在寻找一种方法,使用jquery来点击webListener来播放音频。

1 个答案:

答案 0 :(得分:0)

您可以添加HTML文件的链接,例如

<a href="corona://playsound">Play sound</a>

并且在侦听器功能中,您需要检查以下内容:

local function webListener( event )
    if (event.url and event.url == "corona://playsound") then
        audio.play( soundID )
    end
end

这应该可以解决问题