Music Player
MusicPlayer
is a static global class which allows you to control the in-game music playback i.e. the in-game "Music" menu.
Member Variables¶
Variable | Description | Type |
---|---|---|
loaded | If all players loaded the current audioclip. Read only. | |
player_status | The current state of the music player. Read only. Options: "Stop", "Play", "Loading", "Ready". |
|
playlistIndex | Use playlist_index. Current index of the playlist.-1 if no playlist audioclip is playing. |
|
playlist_index | Current index of the playlist. -1 if no playlist audioclip is playing. |
|
repeat_track | If the current audioclip should be repeated. | |
shuffle | If the playlist should play shuffled. |
Function Summary¶
Functions that interact with the in-game music player.
Function Details¶
getCurrentAudioclip()¶
Gets the currently loaded audioclip.
Returned table
Example
Print the title of the current audioclip.
local clip = MusicPlayer.getCurrentAudioclip()
print("Currently playing '" .. clip.title .. "'")
getPlaylist()¶
Returned table
Example
Print the track number and title of each audioclip making up the playlist.
local playlist = MusicPlayer.getPlaylist()
for i, clip in ipairs(playlist) do
print(i .. " - " .. clip.title)
end
pause()¶
Returns true
if the music player is/was paused, otherwise false
.
Example
Pause the current track.
MusicPlayer.pause()
play()¶
Returns true
if the music player is/was playing, otherwise false
.
Example
Play the current track.
MusicPlayer.play()
setCurrentAudioclip(...)¶
.Sets/loads the specified audioclip.
setCurrentAudioclip(parameters)
Example
Set the current track.
MusicPlayer.setCurrentAudioclip({
url = "https://domain.example/path/to/clip.mp3",
title = "Example"
})
setPlaylist(...)¶
setPlaylist(parameters)
Example
Set the current playlist to include three pieces of music.
MusicPlayer.setCurrentAudioclip({
{
url = "https://domain.example/path/to/clip.mp3",
title = "Example"
},
{
url = "https://domain.example/path/to/clip2.mp3",
title = "Example #2"
},
{
url = "https://domain.example/path/to/clip3.mp3",
title = "Example #3"
}
})
skipBack()¶
Skips to the beginning of the audioclip or if the play time is less than 3 seconds to the previous audioclip in playlist if possible.
Returns true
if skip was successful, otherwise returns false
.
Example
Skip backwards to either the beginning of the audioclip, or the prior audioclip in the playlist.
MusicPlayer.skipBack()
skipForward()¶
Skips to the next audioclip in the current playlist. If the current audioclip is the last of the playlist, loops around to the first audioclip in the playlist.
Returns true
if skip was successful, otherwise returns false
.
Example
Skip to the next audioclip.
MusicPlayer.skipForward()