How would you go about playing & stopping audio in edit mode?

Greetings! :wave:

Recently I’ve been working on a plugin which let’s you browse audio, much like the Toolbox. However, about halfway through I stumbled onto a little issue; How would I go about previewing audio?

This sounds really easy on the surface, but there are some restrictions you need to take into account:

  • I need my audio to be playable in edit mode (aka without running the game).
  • It needs to be stoppable.

Here are some things I’ve tried so far:

  • Inserting an audio into Workspace and SoundService and then calling :Play(). This did not play the sound at all.
  • Using the :PlayLocalSound() function of SoundService. This did play the audio, however, you can’t stop it once it begins.
  • Using the plugin:PlaySound() and plugin:StopSound() functions. This didn’t work as those functions are under [RobloxScriptSecurity].

With all of that said, have any of you been able to tackle this problem and how? Thanks in advance.

5 Likes

Unfortunately it looks like what you’ve tried is all that is available to us at the moment, I haven’t seen or discovered another way to play audio in Studio other than the :PlayLocalSound() function in the SoundService

Might be a topic you could create in Platform Feedback

Here’s a working method (pretty bad, but the only one),
using PlayOnRemove Sounds and SetListener.

You can spawn a part with a sound at the Sound Listener position, then :Destroy() it
When you want to stop all sounds you can :SetListener() to somewhere far, this will set the “3d audio center” position

local listenerCFrame = workspace.Camera.CFrame
function changeListener()
	local r = 1000000
	listenerCFrame = CFrame.new(Vector3.new(math.random(-r,r),math.random(-r,r),math.random(-r,r)))
	local SoundService = game:GetService("SoundService")
	SoundService:SetListener(Enum.ListenerType.CFrame, listenerCFrame)
end
--Call changeListener() to stop all sounds
--Play sounds at "listenerCFrame"
1 Like