MusicControl v2.1.0 | an extremely customizable, yet easy to use music display/control

MusicControl v2.1.0

an extremely customizable, yet easy to use music display/control

MusicControl v2 (formerly MusicPlayer) is a native-like display and control for music within your experience, with full support for all input types.
display

to use MusicControl, simply require the module inside a LocalScript, and create it using MusicControl.new().

displaying

local Music = MusicControl.new()
Music:SetControlState("Shuffle", "Off")
Music:SetControlState("Rewind", "Off")
Music:SetControlState("Skip", "Enabled")
Music:SetControlState("PlayPause", "Enabled")
Music:SetControlState("Repeat", "Off")
Music:SetControlState("Volume", "Enabled")
Music:SetControlState("ProgressBar", "Disabled")

in the MusicControl object, there are 7 different Controls, which can each be Enabled, Disabled, or Off. the default value is Enabled for all controls.
Enabled: the Control is visible, and listening for user input.
Disabled: the Control is visible, however it doesn’t listen for user input.
Off: the Control is no longer visible, and the other Controls will adapt to fill the missing space.

to set the displayed title and artist, call :SetTitle() and :SetArtist().

local Music = MusicControl.new()
Music:SetTitle("cool song 😎")
Music:SetArtist("that one artist")

you can also display where you currently are at in the song with :SetPlaybackLength() and :SetPlaybackPosition()

local Music = MusicControl.new()
Music:SetPlaybackLength(audio.TimeLength)
Music:SetPlaybackPosition(audio.TimePosition)

however, typically you would call :SetPlaybackPosition() inside RenderStepped, so it stays updated as the audio plays.

game:GetService("RunService").RenderStepped:Connect(function()
    Music:SetPlaybackPosition(audio.TimePosition)
end)

interactions

you can detect when interactions occur by listening to built-in events, such as OnPlayPausePressed and OnVolumeAdjust.
for volume changes, you need to listen to the OnVolumeAdjust event, and accordingly update the audio and display.

Music.OnVolumeAdjust:Connect(function(newVolume) 
    -- newVolume will always be a value between 0 and 1
    audio.Volume = newVolume
    Music:SetVolumePosition(newVolume) -- sets the volume slider position
end)

adjustingVolume

similarly, for playback, you listen to the OnPlaybackAdjust event and adjust values accordingly.

Music.OnPlaybackAdjust:Connect(function(newPosition)
    -- newPosition will also always be a value ranging from 0 to 1
    audio.TimePosition = audio.TimeLength * newPosition
    Music:SetPlaybackPosition(audio.TimePosition)
end)

adjustingPlayback

each button has its own event, all of which are listed below
OnShufflePressed
OnRewindPressed
OnPlayPausePressed
OnSkipPressed
OnRepeatPressed
OnVolumePressed - the volume BUTTON, not the slider

with some Controls, you can adjust the “state” (appearance) of the control by setting it
Music:SetPlaying(value: boolean) - Displays pause icon (shown above) if true, otherwise play icon if false
Music:SetShuffle(value: boolean) - Displays filled shuffle icon if true, regular (shown above) if false
Music:SetRepeat(value: RepeatState) - Can be one of three states, "Repeat", "RepeatOne", or "Off" (shown above)
every single Set method has an corresponding Get method, including the methods not mentioned earlier.

Music.OnPlayPausePressed:Connect(function()
    -- the buttons don't pass any parameters
    audio.Playing = not audio.Playing
    Music:SetPlaying(audio.Playing)
end)

playpausepress

Music.OnShufflePressed:Connect(function()
	Music:SetShuffle(not Music:GetShuffle())
end)

adjustingshuffle

simple repeat cycle

local repeats = {"Off", "Repeat", "RepeatOne"}
local repeatIndex = 1
Music.OnRepeatPressed:Connect(function()
	repeatIndex += 1
	if repeatIndex > #repeats then
		repeatIndex = 1
	end
	Music:SetRepeat(repeats[repeatIndex])
	audio.Looped = Music:GetRepeat() == "RepeatOne"
end)

adjustingrepeat

i have a fully working test place, with 5 songs to loop through or shuffle. try it out!

credits:

  • Icon/TopbarPlus - ForeverHD, wouldn’t be possible without this
  • GoodSignal - stravant

changelog [v2.1.0]

  • fixed bug where elapsed time and remaining time weren’t aligned
  • changed most icons to be rounded, mostly noticeable for repeat/shuffle icons

source code: GitHub - jamiw1/MusicControl
https://create.roblox.com/store/asset/91097397617694

16 Likes

From a first glance this seems like a really awsome resource! I’m a big fan of the minimalist UI, my only nitpick would be how clicking certain buttons like shuffle creates a white square within the highlighted circle, which doesn’t look amazing.

Good work!

1 Like

I wonder if this works with custom topbar modules like TopBar+.

1 Like

it does! it’s using Topbar+ actually, so it will have the most compatibility with it compared to other custom topbar modules. not sure about modules besides that, you would need to see compatibility with Topbar+ for those

1 Like