LifeLua 21-08-2025
Documentation for LifeLua, a Lua interpreter for the PS Vita
Loading...
Searching...
No Matches
audio

Playing music and sounds. More...

Detailed Description

Supported formats: .MP3, .WAV, .OGG, .FLAC, .OPUS and tracker modules (.MOD, .XM, .IT, .S3M, ...). The format is picked from the file extension. Any other file is played as raw 16-bit stereo PCM at 48000 Hz.

Every function that takes an audio as its first parameter can also be called as a method:

local music = audio.load("app0:music.ogg")
music:play(true) -- loop forever
while true do
draw.text(10, 10, string.format("%.1f / %.1f s", music:elapsed(), music:duration()), color.new(255, 255, 255))
draw.swapbuffers()
end
Note
Only one audio can play at a time: playing another one replaces the current one.

Functions

audio audio.load (string path)
 
nil audio.play (audio audio, boolean loop)
 
nil audio.stop (audio audio)
 
nil audio.pause (audio audio, boolean pause)
 
boolean audio.playing (audio audio)
 
boolean audio.paused (audio audio)
 
nil audio.seek (audio audio, number seconds)
 
nil audio.volume (audio audio, number left, number right)
 
number audio.duration (audio audio)
 
number audio.elapsed (audio audio)
 
table audio.id3v1 (audio audio)
 
table audio.id3v2 (audio audio)
 
table audio.comment (audio audio)
 
table audio.tags (audio audio)
 

Function Documentation

◆ audio.comment()

table audio.comment ( audio audio)

Gets the Vorbis comments (tags) of an .OGG file

Method form: snd:comment()

Parameters
audioThe audio (.OGG only)
Returns
nil if it isn't an .OGG file, otherwise a table with these string fields:
  • title
  • album
  • artist
  • year
  • comment
  • genre

◆ audio.duration()

number audio.duration ( audio audio)

Gets the total length of an audio

Method form: snd:duration()

Parameters
audioThe audio
Returns
The length in seconds, or nil if it's unknown

◆ audio.elapsed()

number audio.elapsed ( audio audio)

Gets how far an audio has played

Method form: snd:elapsed()

Parameters
audioThe audio
Returns
The current position in seconds, or nil if it's unknown

◆ audio.id3v1()

table audio.id3v1 ( audio audio)

Gets the ID3v1 tag of an .MP3 file

Method form: snd:id3v1()

Parameters
audioThe audio (.MP3 only)
Returns
nil if there is no ID3v1 tag, otherwise a table with these string fields:
  • title
  • artist
  • album
  • comment
  • year
  • tag
  • genre

◆ audio.id3v2()

table audio.id3v2 ( audio audio)

Gets the ID3v2 tag of an .MP3 file

Method form: snd:id3v2()

Parameters
audioThe audio (.MP3 only)
Returns
nil if there is no ID3v2 tag, otherwise a table with these fields:
  • string title
  • string artist
  • string album
  • string comment
  • string year
  • string genre
  • image cover: The album cover (.JPG or .PNG), if there is one

◆ audio.load()

audio audio.load ( string path)

Loads an audio file

Parameters
pathPath to the file (e.g. "app0:music.mp3")
Returns
The loaded audio. Raises an error if the file can't be opened.

◆ audio.pause()

nil audio.pause ( audio audio,
boolean pause )

Pauses or resumes an audio

Method form: snd:pause(pause)

Parameters
audioThe audio
pausetrue to pause, false to resume
Example:
if controls.pressed(SCE_CTRL_START) then
music:pause(not music:paused())
end
SceCtrlButtons SCE_CTRL_START
Start button.
Definition lj_controls.h:47

◆ audio.paused()

boolean audio.paused ( audio audio)

Checks if an audio is paused

Method form: snd:paused()

Parameters
audioThe audio
Returns
true if paused

◆ audio.play()

nil audio.play ( audio audio,
boolean loop )

Starts playing an audio, from the beginning if it wasn't already playing

Method form: snd:play(loop)

Parameters
audioThe audio
looptrue to start over every time it ends (optional, default: false)

◆ audio.playing()

boolean audio.playing ( audio audio)

Checks if an audio is playing

Method form: snd:playing()

Parameters
audioThe audio
Returns
true while the audio is playing (also while it's paused), false once it has finished

◆ audio.seek()

nil audio.seek ( audio audio,
number seconds )

Jumps to a position in the audio

Method form: snd:seek(seconds)

Parameters
audioThe audio
secondsPosition to jump to, in seconds from the start

◆ audio.stop()

nil audio.stop ( audio audio)

Stops the audio output completely. Use audio.pause() if you want to continue later.

Method form: snd:stop()

Parameters
audioThe audio

◆ audio.tags()

table audio.tags ( audio audio)

Gets the tags of an .OPUS file

Method form: snd:tags()

Parameters
audioThe audio (.OPUS only)
Returns
nil if it isn't an .OPUS file, otherwise a table with these fields:
  • string title
  • string album
  • string artist
  • string date
  • string comment
  • string genre
  • image image: The front cover, if there is one

◆ audio.volume()

nil audio.volume ( audio audio,
number left,
number right )

Sets the volume of the audio

Method form: snd:volume(left, right)

Parameters
audioThe audio
leftVolume from 0 to 100 (optional, default: 100)
rightVolume of the right speaker from 0 to 100 (optional, default: same as left)
Example:
music:volume(50) -- half volume
music:volume(100, 0) -- left speaker only