Difference between revisions of "minetest.sound play"

From Minetest Developer Wiki
Jump to navigation Jump to search
Line 5: Line 5:
 
== Description ==
 
== Description ==
 
Plays a sound.
 
Plays a sound.
 +
 +
Only OGG 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>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>.

Revision as of 14:09, 19 January 2013

Syntax

minetest.sound_play(SimpleSoundSpec, SoundParameters)

Description

Plays a sound.

Only OGG files are supported. For positional playing of sounds, only single-channel (mono) files are supported. Otherwise OpenAL will play them non-positionally.

SimpleSoundSpec can be a string with the filename (without the file extention) or a table with the fields name="name" and gain=float.

SoundParameters is a table with the following fields:

  • gain = float: the gain (default 1.0)
  • max_hear_distance = int: the maximum hear distance
  • loop = bool: Sound is looped

The location can be specified with one of the following fields (if none is used, its played locationless to all players):

  • to_player = "playername": Sound is played locationless to the player
  • pos = position: Sound is played at this position
  • object = ObjectRef: Sound is played connected to the object

The function returns a sound hanlder that can be passed to minetest.sound_stop(handle) to stop the sound.

Mbox information.png This article is missing examples.
Feel free to add them.