在Corona SDK中,侦听localfile.html WebView事件的触发。

我正在构建一个简单的应用程序,需要我使用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中的listener函数,在本地html文件中发生事件时播放声音。

在我的page.lua中类似下面这样?

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

我正在寻找一种使用jquery的方法,以触发webListener以播放音频。

点赞
用户1376249
用户1376249

你可以像这样在 HTML 文件中添加链接

<a href="corona://playsound">播放音效</a>

在监听函数中,你需要检查以下内容:

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

这应该能解决问题。

2014-08-09 21:54:16