开发者

How to play sound in lua

How to play sound in lua? Is开发者_运维技巧 there any simple trick how to do it?

My goal is to play some ogg (or mp3) files during playing my game, which is programmed in lua. It's running on windows.


Lua does not have any built-in sound APIs. As you are on Windows, you have these options:

  • Write bindings for a sound system of choice (OpenAL or something more high-level — as a separate non-Lua-specific question if you need help picking one).

  • Use LuaJIT2 FFI to directly access DLL functions of the sound system of choice.

  • Otherwise, if you do not use LuaJIT2, use Alien FFI library.

  • Or, indeed, use LuaCOM to play some sound (with DirectSound?), if you're familiar with COM stuff.


Lua doesn't have any native sound APIs. If there is a plugin/extension for Lua to accomplish audio control/playback, you'd have to go dig that up seperately. Or if Lua supports COM, you could speak to the Windows audio facilities directly.


proteaAudio is a pretty easy library for lua to play audio or even generate audio on the fly.


You can use the Corona library:

--Loads the selected audio (make sure the name is the same as the .wav file)
local audio1 = audio.loadSound( "audio1.wav" )

--Plays the audio on any available channel (theres up to 32 channels)
local audio1Channel = audio.play( audio1 )

source: http://docs.coronalabs.com/api/library/audio/play.html


In windows, use luacom

require('luacom').CreateObject("wmplayer.ocx").URL="my.mp3"--Need to keep host process alive, not to close.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜