Difference between revisions of "minetest.sound play"

From Minetest Developer Wiki
Jump to navigation Jump to search
(Mark as unofficial Lua documentation)
 
Line 1: Line 1:
 
{{UnofficialLua}}
 
{{UnofficialLua}}
 
{{DISPLAYTITLE:minetest.sound_play}}
 
{{DISPLAYTITLE:minetest.sound_play}}
{{Languages}}
+
See [https://minetest.gitlab.io/minetest/minetest-namespace-reference/#sounds minetest.sound_play] in the Lua API documentation, and [https://minetest.gitlab.io/minetest/sounds/ Sounds] for general information about sound parameters.
== Syntax ==
 
<source>minetest.sound_play(SimpleSoundSpec, SoundParameters)</source>
 
 
 
== Description ==
 
Plays a sound.
 
 
 
Only Ogg Vorbis files are supported. For positional playing of sounds, only single-channel (mono) files are supported. Otherwise OpenAL will play them non-positionally.
 
 
 
<code>[[SimpleSoundSpec]]</code> can be a string with the filename (without the file extention) or a table with the fields <code>name="name"</code> and <code>gain=float</code>.
 
 
 
<code>SoundParameters</code> is a table with the following fields:
 
* <code>gain = float</code>: the gain. default = 1.0
 
* <code>max_hear_distance = int</code>: the maximum hear distance. default = 32
 
* <code>loop = bool</code>: Sound is looped. Only sounds connected to objects can be looped. default = false
 
 
 
The location can be specified with one of the following fields in the SoundParameters (if none is used, its played locationless to all players):
 
* <code>to_player = "playername"</code>: Sound is played locationless to the player
 
* <code>pos = [[position]]</code>: Sound is played at this position
 
* <code>object = [[ObjectRef]]</code>: Sound is played connected to the object
 
 
 
The function returns a sound handle that can be passed to <source enclose=none>minetest.sound_stop(handle)</source> to stop the sound.
 
 
 
== Features ==
 
You can play random sound using filename convention <code>modname_soundname.N.ogg</code> (see examples)
 
 
 
== Examples ==
 
 
 
Plays the <code>testmod_testsound.ogg</code> sound at the [[position]] 0,0,0.
 
<source>
 
minetest.sound_play("testmod_testsound", {
 
pos = {x=0, y=0, z=0},
 
max_hear_distance = 100,
 
gain = 10.0,
 
})
 
</source>
 
 
 
Plays the <code>testmod_foobar.ogg</code> sound to player "foo".
 
<source>
 
minetest.sound_play("testmod_foobar", {
 
to_player = "foo",
 
gain = 2.0,
 
})
 
</source>
 
 
 
Plays random <code>testmod_foobar</code> sound.
 
<source>
 
-- testmod/sounds listing:
 
-- /testmod_foobar.1.ogg
 
-- /testmod_foobar.2.ogg
 
-- /testmod_foobar.3.ogg
 
minetest.sound_play("testmod_foobar")
 
</source>
 
  
 
[[Category:Methods|s]]
 
[[Category:Methods|s]]

Latest revision as of 13:50, 25 October 2022

Mbox warning.png This page contains unofficial, low-quality Lua API documentation and is likely to be outdated or wrong. Do not rely on it!
For the official and up-to-date documentation, see Lua API Documentation.
Mbox warning.png This page has been proposed for deletion for the following reason: "Contains unofficial and potentially outdated, redundant and inconsistent Lua API information"
If you don't think that this page should be deleted, please explain why on the talk page.

See minetest.sound_play in the Lua API documentation, and Sounds for general information about sound parameters.