在 Corona SDK 作曲家中,当我重新加载场景时,音频会稍微淡出

In Corona SDK composer, when I reload a scene, audio slightly fades out

在我的 Corona SDK 项目中,我有一个名为 "menu.lua" 的作曲场景(使用 composer.newScene() 创建),它是第一个场景,由 main.lua 文件调用。我只有这个场景的背景音轨,加载到 scene:create() 和 audio.loadSound() 的局部变量中。当我加载另一个场景(假设它是一个 "credit" 场景,静态的,没有音乐、声音、动画、计时器等)然后返回到菜单场景时,音频仍在播放,但音量较低.

音频在通道 2 循环播放,我在 scene:show "did" 阶段使用 audio.play()。我在 scene:hide "will" 阶段使用 audio.fadeOut() ,在 "did" 阶段用 audio.stop() 停止它,然后用 audio.dispose 处理它() 在 scene:destroy.

在"menu.lua"文件中

local composer=require("composer")
local scene=composer.newScene()
local theme --this is the variable for audio

function scene:create(event)
  local sceneGroup=self.view
  theme=audio.loadSound("sfx/theme_short.mp3")
end

function scene:show(event)
  local sceneGroup=self.view
  if event.phase=="will"
    audio.play(theme,{loops=-1,channel=2})
  end
end

function scene:hide(event)
  local sceneGroup=self.view
  if event.phase=="will" then
    audio.fadeOut(theme,{500})
  end
  elseif event.phase=="did" then
    audio.stop(2)
  end
end

function scene:destroy(event)
  local sceneGroup=self.view
  audio.dispose(theme)
end

另一个场景(假设它是 "credits.lua")由一个带有 "tap" 事件的按钮调用。在 "credits.lua" 中,我使用此函数返回到 "menu.lua" 场景(函数是通过附加到按钮的 "tap" 事件调用的)

local function goMenu()
  composer.removeScene("menu")
  composer.gotoScene("menu","slideUp",500)
  return true
end

我已经尝试在 scene:show "did" 阶段和 scene:create 阶段播放音频,但问题仍然存在。所有场景都会出现问题,所有场景都是静态的(总共 3 个)。有什么想法吗?

你应该替换

audio.fadeOut(theme,{500})

audio.fadeOut( { channel=2, time=500 } )

因为你使用了错误的语法。

audio.fadeOut()

请务必阅读文档的 "Gotcha" 部分:

When you fade the volume, you are changing the volume of the channel. This value is persistent and it's your responsibility to reset the volume on the channel if you want to use the channel again later (see audio.setVolume()).

您负责调回频道音量,因为 fadeOut 会改变频道的音量。