跳到主要内容

音频声音(AudioSound)

Audio:play* 返回的播放实例,提供播放控制和音量控制。

字段(Fields)

volume

声音音量。

function update(self: AudioScript)
-- 当输入值变化时更新 AudioSound 的播放音量
if self.soundInstance then
self.soundInstance.volume = self.volumeNumber / 100
end
end

方法(Methods)

stop

停止音频播放。

stop(fadeToStopTime: number?) -> ()
function stopSound(self: AudioScript)
if self.soundInstance then
self.soundInstance:stop()
end
end

seek

将音频定位到指定秒数。

seek(seconds: number) -> ()
if self.soundInstance then
self.soundInstance:seek(self.seekSeconds)
end

seekFrame

将音频定位到指定 PCM 帧。

seekFrame(frame: number) -> ()
if self.soundInstance then
self.soundInstance:seekFrame(self.seekFrameNumber)
end

completed

声音是否已播放完成。

completed() -> boolean
function advance(self: AudioScript, seconds: number): boolean
if self.soundInstance then
self.isCompleted = self.soundInstance:completed() -- 播放是否已完成
end
return true
end

time

当前声音时间(秒)。

time() -> number
function advance(self: AudioScript, seconds: number): boolean
if self.soundInstance then
self.currentTime = self.soundInstance:time() -- 当前播放时间(秒)
end
return true
end

timeFrame

当前声音时间(PCM 帧)。

timeFrame() -> number
function advance(self: AudioScript, seconds: number): boolean
if self.soundInstance then
self.currentTimeFrame = self.soundInstance:timeFrame() -- 当前播放时间(PCM 帧)
end
return true
end

pause

暂停音频播放。

pause() -> ()
function pauseSound(self: AudioScript)
if self.soundInstance then
self.soundInstance:pause()
end
end

resume

从当前位置恢复音频播放。

resume() -> ()
function resumeSound(self: AudioScript)
if self.soundInstance then
self.soundInstance:resume()
end
end

play

播放音频。

play() -> ()
function playSound(self: AudioScript)
if self.soundInstance then
self.soundInstance:play()
end
end