Garry's Mod Wiki

Revision Difference

sound.PlayFile#518058

<function name="PlayFile" parent="sound" type="libraryfunc"> <description> Plays a file from GMod directory. You can find a list of all error codes [here](http://www.un4seen.com/doc/#bass/BASS_ErrorGetCode.html) For external file/stream playback, see <page>sound.PlayURL</page>. <bug issue="1752">This fails for looping .wav files in 3D mode.</bug> <bug issue="2304">This fails with unicode file names.</bug> </description> <realm>Client</realm> <args> <arg name="path" type="string">The path to the file to play.&#xA;&#xA;Unlike other sound functions and structures, the path is relative to `garrysmod/` instead of `garrysmod/sound/`</arg>⤶ <arg name="flags" type="string">Flags for the sound. Can be one or more of following, separated by a space (&quot; &quot;):&#xA;* 3d - Makes the sound 3D, so you can set its position&#xA;* mono - Forces the sound to have only one channel&#xA;* noplay - Forces the sound not to play as soon as this function is called&#xA;* noblock - Disables streaming in blocks. It is more resource-intensive, but it is required for &lt;page&gt;IGModAudioChannel:SetTime&lt;/page&gt;.&#xA;&#xA;&#xA;&#xA;&#xA;If you don&#x27;t want to use any of the above, you can just leave it as &quot;&quot;.</arg>⤶ <arg name="callback" type="function">Callback function that is called as soon as the the stream is loaded. It has next arguments:&#xA;&#xA;&#xA;&lt;page&gt;IGModAudioChannel&lt;/page&gt; soundchannel - The sound channel. Will be nil if an error occured.&#xA;&#xA;&#xA;&lt;page&gt;number&lt;/page&gt; errorID - ID of an error if an error has occured. Will be nil, otherwise.&#xA;&#xA;&#xA;&lt;page&gt;string&lt;/page&gt; errorName - Name of an error if an error has occured. Will be nil, otherwise.</arg>⤶ <arg name="path" type="string">The path to the file to play.⤶ Unlike other sound functions and structures, the path is relative to `garrysmod/` instead of `garrysmod/sound/`</arg>⤶ <arg name="flags" type="string">Flags for the sound. Can be one or more of following, separated by a space (" "):⤶ * 3d - Makes the sound 3D, so you can set its position⤶ * mono - Forces the sound to have only one channel⤶ * noplay - Forces the sound not to play as soon as this function is called⤶ * noblock - Disables streaming in blocks. It is more resource-intensive, but it is required for <page>IGModAudioChannel:SetTime</page>.⤶ ⤶ ⤶ ⤶ ⤶ If you don't want to use any of the above, you can just leave it as "".</arg>⤶ <arg name="callback" type="function">Callback function that is called as soon as the the stream is loaded. It has next arguments:⤶ ⤶ ⤶ <page>IGModAudioChannel</page> soundchannel - The sound channel. Will be nil if an error occured.⤶ ⤶ ⤶ <page>number</page> errorID - ID of an error if an error has occured. Will be nil, otherwise.⤶ ⤶ ⤶ <page>string</page> errorName - Name of an error if an error has occured. Will be nil, otherwise.</arg>⤶ </args> </function> <example> <description>Plays a piece of music from Half-Life 2.</description> <code> sound.PlayFile( "sound/music/hl2_song12_long.mp3", "noplay", function( station, errCode, errStr ) if ( IsValid( station ) ) then station:Play() else print( "Error playing sound!", errCode, errStr ) end end ) </code> </example>