lua music player

lua music player

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
BigHead
Posts: 145
Joined: 12 Jul 2007, 18:55

lua music player

Post by BigHead »

Skip to the next post for info on music player.

Old thread name: call-out request: PlayOggFile(yes I want to make a music w.)

I know that AF tried to make a music player for Spring as a groupAI but complained about the lack of data avaliable to groupAIs. What he did is a good workaround but not a good solution.
Today I woke up and reallized (really, that's how it happened) that lua has all the necessary call-ins and call-outs to make a perfect music widget. However it's still missing one crucial call-out: PlayOggFile. I prefer the ogg format becouse:
- it's more modern than mp3 (smaller files)
- it has no license issues (I know there are some with mp3 but not sure what)
- it's open source so all you need to do is some copy&pasting (== joke, I know it's not easy and that I'm asking for a lot :wink: )

API:
PlayOggFile(filename, [volume, x, y, z]) -> soundLength, oggID
StopOgg(oggID, [fadeOutTime]) -> nil

PlaySoundFile can be used as a substitute for PlayOggFile before it's implemented so I can just convert mp3s from AFs musicAI into low-bitrate wavs and start working on the widget right now. All I need is a positive reply that the call-out will be implemented in the next release.

What do you think?

Edit: Btw StopSound(soundID) for the current PlaySoundFile would be useful as well.
User avatar
BigHead
Posts: 145
Joined: 12 Jul 2007, 18:55

Post by BigHead »

Lua music player:
More appropriate name for this widget would be: Low quality lua "mp3" player.
I made this player as a substitute until lua is given some serious music-playing capabilities. However my request was ignored so I'm releasing it as it is. If you're a lua scripter check out how I achieved pause/stop/next function using PlaySoundFile() which doesn't support it. You'll propably LOL. Otherwise don't bother downloading it.

Install:
Copy your mp3's to LuaUI/music folder (OTA music from dynamic music AI is recommended).
Run convertAll.bat in the same folder.
Start spring, music should start playing immediately.

Supported commands:
/luaui play
/luaui pause
/luaui stop
/luaui next

Download:
http://www.unknown-files.net/3579/lua_music_player/
Last edited by BigHead on 30 Sep 2007, 17:56, edited 1 time in total.
User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Post by BrainDamage »

haskish solution is hackish! :P yeah, chunking files so you use the file name as seek position is really kind of sad, too bad spring doesn't support a more proper solution :evil:

---------------------------------------------

may i sugest you to start adding a sort of even-driven playlist?

eg.
naval battles: triggered when 30%+ of army ships have attack orders
air raid: 50%+ of the bombers have attack orders
expansion: no battles under run
superweapon: stockpiled weapon is firing
custom events: mod-defined callable by widgets API interface
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

To be precise this isnt an mp3 player at all.

Its a .wav player, so be warned the mp3 OTA soundtrack of 20-40MB will balloon into a folder of several hundred megabytes of wav files.
User avatar
BigHead
Posts: 145
Joined: 12 Jul 2007, 18:55

Post by BigHead »

Brain Damage: Good suggestions. However the sound output is too crappy to use it as the basis of a serious dynamic music widget.

AF: Name of the thread is lua music player as well as the name of the file at UF. I've corrected the post to show music instead of mp3 as well.
Size of the wav files after conversion is 42MB (mp3s: 30MB).
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

I take it the reason the file size increase is so small is due to the quality of the wav files?
User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Post by BrainDamage »

he downsampled the wavs from 44.1 KHz to 11.2 KHz, hence he reduced the side to 1/4 towards "normal" wavs

the loss of quality is obviously huge, but without an proper codec compression i guess there isn't much else you can do (besides not downsampling them :P )
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Post by jK »

However my request was ignored so I'm releasing it as it is.
The request isn't new and you will find 100% more than two posts in this forum about it.

Also trepan already said why it isn't supported yet. Here again:
Spring uses 2 different sound systems, OpenAL and DirectSound (under m$). As trepan is using linux, he has no interests to spend time on the second one. He is only willing to add mp3 support for OpenAl, but as long as not both sound systems have such a support it would be useless ...


Note: because you already convert mp3s to wav, you can start iirc any program with luaUI, so you can also give command params to winamp or any other (lightweight) mp3 player :roll:
User avatar
BigHead
Posts: 145
Joined: 12 Jul 2007, 18:55

Post by BigHead »

I should have searched the forum before posting the request. However you knew the answer so you could have at least told me that it's been discussed before.

Now back on topic.
you can start iirc any program with luaUI
That's great news. There must be some command line mp3 player avaliable so it's possible to make full-quality lua music player after all. I have one question. How do I start a program from lua? I know your knowledge of spring lua is very good so you can propably help me.

In other news. I upgraded this widget into a simple dynamic music player. It starts playing battle music on these events:
- Your unit anywhere on the map takes damage.
- Allied unit in the view takes damage.
- You issue an attack order (attack, area_attack, fight)

... and it works very well :-)
I'll upload it after some testing.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Post by jK »

os.execute() (lua tut)
User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Post by BrainDamage »

you could use mplayer it's primary a movie player, but works great for audio too, and it's cross platform, it's only a bit heavy in the size (9 MB), but takes basically no cpu here ( < 0.1% while playing music files) and self contains all necessary codecs

while you might have to ship the exec for windows installations, you can pretty much assume linux distros already ship it or provide all the facilities to install it easily

run in slave mode and it will accept commands from stdin instead of key bindings
User avatar
BigHead
Posts: 145
Joined: 12 Jul 2007, 18:55

Post by BigHead »

jK: Thanks, I was looking at that page yesterday but missed that method somehow.
Brain Damage: I have a problem with mplayer.
User avatar
BlueTemplar
Posts: 314
Joined: 28 Oct 2007, 22:37

Re: lua music player

Post by BlueTemplar »

Could someone please upload it? Thank you.
User avatar
LOrDo
Posts: 1154
Joined: 27 Feb 2006, 00:21

Re: lua music player

Post by LOrDo »

User avatar
BlueTemplar
Posts: 314
Joined: 28 Oct 2007, 22:37

Re: lua music player

Post by BlueTemplar »

If I'm asking for this one, it's because I can't use the other on my current computer.
Post Reply

Return to “Lua Scripts”