wiki.sine.space | sinespace

Difference between revisions of "Scripting/SSceneBackgroundMusic"

From wiki.sine.space
Jump to: navigation, search
(Replaced content with "This page has moved to: https://docs.sine.space/v/scripting/client-scripting/components/sscenebackgroundmusic")
 
Line 1: Line 1:
=Members=
+
This page has moved to: https://docs.sine.space/v/scripting/client-scripting/components/sscenebackgroundmusic
{{ScriptFunction|void|OnTrackChange|(Closure o)|Function will be called when track changes. |5=<pre>otc = function(trackInfo)
+
Space.Log(trackInfo.Title)
+
Space.Log(trackInfo.Artist)
+
  end
+
Space.Host.ExecutingObject.Radio.OnTrackChange(otc)</pre> |6=<pre>--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)</pre>}}
+
 
+
{{ScriptFunction|void|OnUpcomingTrackChange|(Closure o)|Function will be called when there's an upcoming track change|5=<pre>otc = function(trackInfo)
+
Space.Log(trackInfo.Title)
+
Space.Log(trackInfo.Artist)
+
  end
+
Space.Host.ExecutingObject.Radio.OnUpcomingTrackChange(otc)</pre>|6=<pre>--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)</pre>}}
+
 
+
{{ScriptFunction|void|Play|()|Plays the radio stream|5=<pre>Space.Host.ExecutingObject.Radio.Play()</pre>|6= <pre> --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) </pre>}}
+
 
+
{{ScriptFunction|void|PlayMP3Stream|(string url)|Sets the given MP3 stream url as current stream|5=<pre>Space.Host.ExecutingObject.Radio.PlayMP3Stream("http://stream.example.org:1234/")</pre>}}
+
 
+
{{ScriptFunction|void|PlayVorbisStream|(string url)|Sets the given Vorbis stream url as current stream|5=<pre>Space.Host.ExecutingObject.Radio.PlayVorbisStream("http://stream.example.org:1234/")</pre>}}
+
 
+
{{ScriptFunction|void|Stop|()|Stops playing the radio stream|5=<pre>Space.Host.ExecutingObject.Radio.Stop()</pre>|6=<pre>--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)</pre>}}
+
 
+
 
+
 
+
=Properties=
+
 
+
{{ScriptFunction|bool|Enabled|{ get; set; }|Is this component Enabled?|5= <pre>Space.Host.ExecutingObject.Radio.Enabled = true</pre>|6=<pre>--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)</pre>}}
+
 
+
{{ScriptFunction|string|URL|{ get; }|URL of the current stream|5= <pre>streamURL = Space.Host.ExecutingObject.Radio.URL </pre>|6=<pre>--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)</pre>}}
+
 
+
 
+
 
+
 
+
{{Scripting Navbox}}
+

Latest revision as of 06:21, 19 September 2022

This page has moved to: https://docs.sine.space/v/scripting/client-scripting/components/sscenebackgroundmusic