1

我正在尝试创建 3 个间隔为 10 秒的通知。但是,它只播放第一个声音,并以 10 秒的间隔永远重复。你能检查我的代码并告诉我我做错了什么吗?

local futureTime = 10  --10 seconds 
local sounds =  {"Icebaby.mp3", "Pokemon.mp3", "Yoshi.mp3"}
i=1

local options = {
 alert = "Wake up!",
 sound = "Icebaby.mp3" ,
 custom = { msg = "Alarm" }
}

local notificationID = system.scheduleNotification( futureTime, options )

local function notificationListener( event )

system.cancelNotification(notificationID)
i=i+1
options.sound=sounds[i]
    if(i>3) then
    Runtime:removeEventListener ( "notification", notificationListener )

    else 
        notificationID = system.scheduleNotification( futureTime, options )
    end
end


Runtime:addEventListener( "notification", notificationListener )
4

1 回答 1

0

第一个问题:“它只播放第一个声音”-> 是的,因为您没有更改选项表。所以它总是这个选项表:

local options = {
 alert = "Wake up!",
 sound = "Icebaby.mp3" ,
 custom = { msg = "Alarm" }
}

每次创建下一个通知时更改选项表。例如使用你的“声音”表!

于 2013-07-23T13:31:13.983 回答