# SSceneBackgroundMusic

## Index

### Functions Index

| Function Name                                                                                                                                                                                                                    |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| void [**Play** ](#play)()                                                                                                                                                                                                        |
| void [**PlayMP3Stream** ](#playmp3stream)(string url)                                                                                                                                                                            |
| void [**PlayVorbisStream** ](#playvorbisstream)(string url)                                                                                                                                                                      |
| void [**Stop** ](#stop)()                                                                                                                                                                                                        |
| <p>void <a href="#ontrackchange"><strong>OnTrackChange</strong> </a>(Closure o)<br>void <a href="#ontrackchange"><strong>OnTrackChange</strong> </a>(Action< STrackInfo > trackInfoCallback)</p>                                 |
| <p>void <a href="#onupcomingtrackchange"><strong>OnUpcomingTrackChange</strong> </a>(Closure o)<br>void <a href="#onupcomingtrackchange"><strong>OnUpcomingTrackChange</strong> </a>(Action< STrackInfo > trackInfoCallback)</p> |

### Properties Index

| Property Name                                   |
| ----------------------------------------------- |
| bool [**Enabled** ](#enabled)`get` `set`        |
| string [**URL** ](#url)`get`                    |
| SGameObject [**GameObject** ](#gameobject)`get` |

## Functions

### Play

void **Play** ()

*Plays the radio stream*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Radio.Play()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
 --this script will let us click a radio to make it start playing
--(Example: clicking a light switch toggle's a parent light bulb's intensity)
--[Requires a "Shoutcast Streaming" component on the parent of this object]

thisGameObject = Space.Host.ExecutingObject
IsPlaying = false


StartPlaying = function()
thisGameObject.Radio.Play()
IsPlaying = true
end

StopPlaying = function()
thisGameObject.Radio.Stop()
IsPlaying = false
end


OnClick = function()
    if IsPlaying then
      StopPlaying()
    else
      StartPlaying()
    end
end

thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip="Toggle Play/Stop"
thisGameObject.Clickable.OnClick(OnClick) 
```

{% endtab %}
{% endtabs %}

### PlayMP3Stream

void **PlayMP3Stream** (string url)

*Sets the given MP3 stream url as current stream*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Radio.PlayMP3Stream("http://stream.example.org:1234/")
```

{% endtab %}
{% endtabs %}

### PlayVorbisStream

void **PlayVorbisStream** (string url)

*Sets the given Vorbis stream url as current stream*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Radio.PlayVorbisStream("http://stream.example.org:1234/")
```

{% endtab %}
{% endtabs %}

### Stop

void **Stop** ()

*Stops playing the radio stream*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Radio.Stop()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--this script will let us click a radio to make it start playing
--(Example: clicking a light switch toggle's a parent light bulb's intensity)
--[Requires a "Shoutcast Streaming" component on the parent of this object]

thisGameObject = Space.Host.ExecutingObject
IsPlaying = false


StartPlaying = function()
thisGameObject.Radio.Play()
IsPlaying = true
end

StopPlaying = function()
thisGameObject.Radio.Stop()
IsPlaying = false
end


OnClick = function()
    if IsPlaying then
      StopPlaying()
    else
      StartPlaying()
    end
end

thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip="Toggle Play/Stop"
thisGameObject.Clickable.OnClick(OnClick)
```

{% endtab %}
{% endtabs %}

### OnTrackChange

void **OnTrackChange** (Closure o)\
void **OnTrackChange** (Action<[ STrackInfo](https://docs.breakroom.tech/scripting/client-scripting-api-reference/types/strackinfo) > trackInfoCallback)

*Function will be called when track changes.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
otc = function(trackInfo)
  end
Space.Host.ExecutingObject.Radio.OnTrackChange(otc)
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--this script will update a UIText object with the track title on track change
--[this GameObject needs a "Shoutcast Streaming"/"SceneBackgroundMusic" component]

thisObj = Space.Host.ExecutingObject

text = Space.Host.GetReference("Text") -- set in Scripting Runtime references

otc = function(trackInfo)
text.UIText.Text = "Track: " .. trackInfo.Title .. " by " .. trackInfo.Artist
end

thisObj.Radio.OnTrackChange(otc)
```

{% endtab %}
{% endtabs %}

### OnUpcomingTrackChange

void **OnUpcomingTrackChange** (Closure o)\
void **OnUpcomingTrackChange** (Action< [STrackInfo](https://docs.breakroom.tech/scripting/client-scripting-api-reference/types/strackinfo) > trackInfoCallback)

*Function will be called when there's an upcoming track change*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
otc = function(trackInfo)

end
Space.Host.ExecutingObject.Radio.OnUpcomingTrackChange(otc)
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--this script will update a UIText object with the track title on upcoming track change
--[this GameObject needs a "Shoutcast Streaming"/"SceneBackgroundMusic" component]

thisObj = Space.Host.ExecutingObject

text = Space.Host.GetReference("Text") -- set in Scripting Runtime references

outc = function(upcomingTrackInfo)
text.UIText.Text = "Track: " .. upcomingTrackInfo.Title .. " by " .. upcomingTrackInfo.Artist
end

thisObj.Radio.OnUpcomingTrackChange(outc)
```

{% endtab %}
{% endtabs %}

## Properties

### Enabled

bool **Enabled** `get` `set`

*Is this component Enabled?*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Radio.Enabled = true
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--clicking this object will Enable/Disable it's Scene Background Music component
thisGameObject = Space.Host.ExecutingObject
component = thisGameObject.Radio

OnClick = function()
component.Enabled =  not component.Enabled
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)
```

{% endtab %}
{% endtabs %}

### URL

string **URL** `get`

*URL of the current stream*

{% tabs %}
{% tab title="Lua" %}

```lua
streamURL = Space.Host.ExecutingObject.Radio.URL 
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--this script will update a UIText object with the current stream URL
--[this GameObject needs a "Shoutcast Streaming"/"SceneBackgroundMusic" component]

thisObj = Space.Host.ExecutingObject

text = Space.Host.GetReference("Text") -- set in Scripting Runtime references


OnUpdate = function()
text.UIText.Text = thisObj.Radio.URL
end

thisObj.OnUpdate(OnUpdate)
```

{% endtab %}
{% endtabs %}

### GameObject

[SGameObject](https://docs.breakroom.tech/scripting/client-scripting-api-reference/types/sgameobject) **GameObject** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
theGameObject = Space.Host.ExecutingObject.Floor.GameObject
```

{% endtab %}
{% endtabs %}
