Help with Derma

I’m try to make a simple derma window that plays music when it opens, and then it’s supposed to display a label when it starts playing that music, but I’m unable to get the label to appear. Here is the current code that I have:


Window = {};

local function ShowDermaWindow()
  Window.Frame = vgui.Create("DFrame");
  Window.Frame:SetVisible(true);
  Window.Frame:Center();
  Window.Frame:SetSize(ScrW() * .60, ScrH() * .5);
  Window.Frame:MakePopup();

  function Window.Frame:Paint(w,h)
    draw.RoundedBox(0, 0, 0, w, h, Color(135, 50, 50, 255));
  end

  sound.PlayURL("url", "false;false;false;false", function(station)
    if (IsValid(station)) then
      station:Play();
      
      Window.Label = vgui.Create("DLabel", Window.Frame)
      Window.Label:SetText("Audio is playing..........");
      Window.Label:SetPos(40, 40)
    end
  end);
end

I do not get any errors in my console which I found odd, but it does work when I put it outside of the sound.PlayURL callback. However this doesn’t help me much as it should only display the text if it determines that music is playing.

Any help would be appreciated.

Add print statements to find where it’s breaking

What is up with your flags? If you don’t want to set any, then leave it as an empty string… Nowhere on the wiki does it say to add “false” and separate them with “;”, you separate flags with spaces…

“f you don’t want to use any of the above, you can just leave it as “”.”

Alternatively, why don’t you create the label outside, below the Frame, and set the text when the sound loads? Also, if you don’t plan on referencing Window.Label outside of the function scope, you should just have it as a local variable, parented to the frame.

I did that and it seems that none of the code in the sound.PlayURL callback is being executed.

I also fixed the flags in the 2nd argument of that same method.

Also while the callback seems to be getting ignored for some reason, it still does play the music, even without calling station:Play() (I’m not sure if that’s normal, but it doesn’t seem to be)

Once again… if you look in the wiki…

Also…



sound.PlayUrl( "", "noplay", function( Station, ErrorID, ErrorName )
    if ( IsValid( Station ) ) then
        print( "Valid" )
    else
        print( ( "Invalid: %s %s" ):format( ErrorID, ErrorName ) )
    end
end )


So sorry sir. My confusion was because most of where I see it used without that flag, people still call audio:Play().

Please forgive me, please. I’m so sorry.

I’ll… consider forgiving you. Test out the sample code I just posted. If it works, it’ll print valid, otherwise it’ll give you an error id along with the name of the error.