How do you play a sound exclusively?

Is there any way to play a sound to a player and make sure it is the only thing they hear? (No explosion screeches, no weapon fire, no other player footsteps, no flatline, nothing)

The best you can do is run “stopsound” on the player and hope nothing else plays

I was afraid that would be the only ‘solution’.

I mean obviously if you want it to be the only sound you would have to stop all the other sounds before playing it

The thing is, it’s actually 24 second piece of audio (played when the player dies). stopsound is perfect for starting it but not much more after 1-2 seconds.

run stopsound every second?

That will obviously stop the sound OP needs playing and is still hardly ideal.

use this.

And run stopsound and straight after run play. It then seems like the sound never stops.


sound.PlayFile( "sound/music/vlvx_song22.mp3", "", function( station )
	if IsValid( station ) then station:Play() end
	hook.Add("Tick", "exclusivesound",function()
		LocalPlayer():ConCommand("stopsound")
		if IsValid( station ) then
			station:Play()
		else
			hook.Remove("Tick", "exclusivesound")
		end
	end)
end )


Something like that. Edit it to your taste.

EDIT:

You are probably going to have to call:


if station:GetState() == GMOD_CHANNEL_STOPPED then hook.Remove("Tick", "exclusivesound") end

Because I guess it otherwise might not stop the stopsound.(I guess it wont become Invalid This wont remove the hook)

You could try using awesomium core to play the sound setting “volume 0” when the audio starts and afterwards “volume {original value}” when the audio ends. Awesomium Core uses a different process than Garry’s Mod allowing it to bypass the source audio channel system

(I would recommend making the panel invisible)

Perfect! That worked exactly as I wanted. Thank you so much.
However, is there a way to have it play a local file (currently I’m using a website to host it.)

Really? Wow
I thought of that solution while pooping on the toilet

This might just be me being an idiot, but can’t you use

surface.PlaySound?

Depending.
If he downloadedir on the client, yes, but if its just a website “live” sound, as for example youtube, no, wich i dont remember the method now

A hacky method for YouTube could be:



local html = vgui.Create( "DHTML" )
html:OpenURL( 'VIDEO_URL' )
html:SetVisible( false )


But then the panel would still exist when the video ended, and autoplay might be on

Regarding this, is there any way to set awesomonium’s volume? Sometimes I want to mute a DHTML but rip I don’t know how

You need to create an API with the audio source that allows you to adjust the volume inside the panel
I would recommend using JavaScript to create the API and then have lua call functions you set to change the volume (now that I think if it, it’s not an API at all)