Garry's Mod Wiki

sound.PlayURL

sound.PlayURL( string url, string flags, function callback )

Description

Allows you to play external sound files, as well as online radio streams. You can find a list of all error codes here

For offline file playback, see sound.PlayFile.

Due to a bug with BASS, AAC codec streams cannot be played in 3D mode.

Issue Tracker: 2296

Arguments

1 string url
The URL of the sound to play
2 string flags
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 IGModAudioChannel:SetTime.

If you don't want to use any of the above, you can just leave it as "".

3 function callback
Callback function that is called as soon as the the stream is loaded. It has next arguments:

IGModAudioChannel soundchannel - The sound channel

number errorID - ID of an error, if an error has occured

string errorName - Name of an error, if an error has occured

Example

Example usage of the function.

local g_station = nil sound.PlayURL ( "URL", "3d", function( station ) if ( IsValid( station ) ) then station:SetPos( LocalPlayer():GetPos() ) station:Play() -- Keep a reference to the audio object, so it doesn't get garbage collected which will stop the sound g_station = station else LocalPlayer():ChatPrint( "Invalid URL!" ) end end )

Page Links


Special Pages


Wikis

?

Render Time: 45ms

DB GetPage 4
Generate Html 17
SaveChanges (1) 9
Render Body 0
Render Sidebar 13