What is the problem ?
[CODE]
local Audiosource = nil
local function TestSound()
sound.PlayURL( link, "mono", function(source)
if IsValid(source) then
if IsValid(Audiosource)then
print(Audiosource)
Audiosource:Stop()
Audiosource = nil
else
print(source)
Audiosource = source
Audiosource:Play()
end
else
print(err)
end
end)
end
--print(Audiosource)
TestSound()
// Was printed "nil"
[/CODE]
Seems right to me. Audiosource is nil until you set it to source.
[QUOTE=code_gs;51994934]Seems right to me. Audiosource is nil until you set it to source.[/QUOTE]
I set it "Audiosource = source" , or it not work ?
are you sure your url is correct? the callback has two other parameters, errorid and errorname. see what they say
[QUOTE=_Chewgum;51994989]are you sure your url is correct? the callback has two other parameters, errorid and errorname. see what they say[/QUOTE]
I don't get error. Music is playing , i want stop music if AudioSource is valid , but it's not work : /
how are you executing the function to test it?
TestSound() - play and set Audiosource to source
TestSound() - stop Audiosource and remove it
?
[QUOTE=_Chewgum;51995275]how are you executing the function to test it?
TestSound() - play and set Audiosource to source
TestSound() - stop Audiosource and remove it
?[/QUOTE]
Yes it is
with "local Audiosource = nil" , what bool return "if IsValid(Audiosource)then" ?
It's possible to juste put :
local Audiosource (to leav them full blanc) ?
and you use "Audiosource:Play()". Can you use "Audiosource:Remove()" and not "= nil" ?
I think the problem cam from "if IsValid(Audiosource)then".
If Audiosource is valid, you are just setting it to nil and not setting it to the new channel[code]local Audiosource = nil
local function TestSound()
sound.PlayURL( link, "mono", function(source)
if IsValid(source) then
if IsValid(Audiosource)then
print(Audiosource)
Audiosource:Stop()
Audiosource = nil
end
print(source)
Audiosource = source
Audiosource:Play()
else
print(err)
end
end)
end
--print(Audiosource)
TestSound()
// Was printed "nil"[/code]
[QUOTE=Nyhu;51995384]
I think the problem cam from "if IsValid(Audiosource)then".[/QUOTE]
Yes , problem is this. How to fix it?
[CODE]local link = "https://dl.dropboxusercontent.com/s/a1t9z7i3sg41s63/x1fLtfaALxhs.128.mp3?dl=0"
local Audiosource
local function TestSound()
sound.PlayURL( link, "mono", function(source)
if IsValid(source) then
print("Source is valid")
if IsValid(Audiosource)then
print("Audiosource is valid")
Audiosource:Stop()
Audiosource = nil
end
Audiosource = source
Audiosource:Play()
else
print(err)
end
end)
end
TestSound()[/CODE]
And output :
[IMG]https://i.imgur.com/tcPvtXI.png[/IMG]
try making Audiosource a global ?
[QUOTE=_Chewgum;51995595]try making Audiosource a global ?[/QUOTE]
Its work, thanks.
I tried before but it didn't work : / Bug ?
Sorry, you need to Log In to post a reply to this thread.