【问题标题】:Listen for localfile.html webview event to be triggered in corona sdk监听在 corona sdk 中触发的 localfile.html webview 事件
【发布时间】:2015-01-06 17:13:39
【问题描述】:

我正在构建一个需要我使用 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 )

页面拉起并呈现良好

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

在我的 page.lua 中有这样的东西吗?

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

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

【问题讨论】:

    标签: webview lua listener coronasdk


    【解决方案1】:

    您可以添加指向您的 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
    

    这应该可以解决问题

    【讨论】:

    • 谢谢,但是当我点击链接时,它会转到 404 类型的页面
    • 奇怪,无论如何......你总是可以使用 ​​Playsound 但你需要在 event.url 字符串中搜索“playsound”子字符串
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-01
    • 2012-02-26
    • 1970-01-01
    • 2014-10-19
    • 1970-01-01
    • 1970-01-01
    • 2014-04-22
    相关资源
    最近更新 更多