sound.PlayURL only plays for a few seconds.

So I was thinking of trying out this sound stream and I am able to get it to work but after a few seconds it fades out stops playing .
I have tried different streams and they all do the same thing, am I missing a loopback or something stupid here? Any help is appreciated.



	sound.PlayURL( "http://108.61.30.179:4010", "3d", function( station )
		if ( IsValid( station ) ) then
			station:SetPos( Vector(0,0,0) )
			station:Play()
		end
	end)

I assume you’re at vector zero when playing the sound and not moving?

Yeah, I am at the same location as the sound is. It just stops playing after a few seconds.

edit
And it seems that when the window is not infocus it takes stops playing a little longer than it would when being ingame.
Callback shows no errors either.

Try playing a different sound and see if there are any improvements. Here’s a sample sound for you:

Yeah, that sound worked. Maybe the radio stream has some sort of timeout or something? The streams I am trying to get are from shoutcast so maybe its just them? I am gonna try a different stream site and see if its just shoutcast being stupid. When the streams play they seem to have a weird echo to them too.

edit
I have tried multiple different stream sites and it seems that every stream I try just stops playing after a few seconds. Only files that aren’t streams like yours work fine. Hmm… :suicide:
Maybe it is a timeout or sound catchup problem that may be causing it?

Radio streams are endless and are getting stopped by the garbage collection if the handle gets out of scope.

Streams that have an end like an mp3 file will be freed when the stream is stopped or when it ends.

This prevents you from playing a stream without being able to stop it in Lua.

I can load the stream from shoutcast so they turn into something like, “http://108.61.30.179:4010/;stream.mp3”. But even then it still cuts out after a few seconds. :expressionless: I also tried the .wav but it seems to do the same thing.

So how would I gain the ability to make it work? I never touched any garbage collection stuff so I can’t see myself what exactly is causing it to do that.

It’s not about the name it’s about the content itself! Endless is endless.
Garbage collection is build into Lua and is automated it removes variables from the memory if you can’t reach them anymore. You should google it.

In your case you can make it work like this:



g_station = nil
sound.PlayURL( "http://108.61.30.179:4010", "3d", function( station )
    if ( IsValid( g_station ) ) then g_station:Stop() end
    if ( IsValid( station ) ) then
        station:SetPos( Vector(0,0,0) )
        station:Play()
        g_station = station -- save the handle somewhere, so it doesn't get gc'd.
    end
end)


The variable g_station can be a local too, but you need to know what you do. You can save a variable to an entity too if you need it in a per entity context.

Thanks, that works. Haven’t been at home for a while to post but thanks for the help.

Does the IGModAudioChannel:GetFileName() (BASS) have any alternative to get an actual track name or title instead of returning the URL?

If you absolutely need the file name, I made this a while ago.

Edit: nvm this doesn’t work with streams