2

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.

2
  • 1
    Did you use any framework (like Löve) to program your game? Commented Mar 20, 2011 at 0:19
  • I use only VCL GUI lib. It's interactive fiction. Commented Mar 20, 2011 at 19:33

5 Answers 5

5

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.

2

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.

1
  • ...Though I would not recommend it as a solution for the sound in game. Better to bind some familiar C library (or find existing bindings). Commented Mar 20, 2011 at 0:59
1

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

0
1

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

0

In windows, use luacom

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.