Audio Player


Node Information
Plays the specified sound file. Select a sound file and call 'Play', you can also Stop or Pause by calling 'Stop' or 'Pause'.
General Information
• This node doesn't have other available options.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
Play IN RUN MULTIPLE FALSE FALSE
Pause IN RUN MULTIPLE FALSE FALSE
Stop IN RUN MULTIPLE FALSE FALSE
File IN String MULTIPLE FALSE FALSE
Volume IN Double ONE FALSE FALSE
Speed IN Double ONE FALSE FALSE
TrackBar IN Object MULTIPLE FALSE FALSE
Ready OUT RUN MULTIPLE FALSE FALSE
Ended OUT RUN MULTIPLE FALSE FALSE
Length OUT TimeSpan MULTIPLE FALSE FALSE
Position OUT TimeSpan MULTIPLE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.Media.Audio
{
    [IsNode("Audio Player")]
    public class AudioPlayer : Node
    {
        Port play = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Play");
        Port stop = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Stop");
        Port pause = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Pause");
        Port file = new Port(PortType.IN, typeof(string), AcceptsLinks.MULTIPLE, "File");
        Port vol = new Port(PortType.IN, typeof(double), AcceptsLinks.ONE, "Volume");
        Port speed = new Port(PortType.IN, typeof(double), AcceptsLinks.ONE, "Speed");
        Port trackbar = new Port(PortType.IN, typeof(object), AcceptsLinks.MULTIPLE, "TrackBar");
        Port length = new Port(PortType.OUT, typeof(TimeSpan), AcceptsLinks.MULTIPLE, "Length");
        Port position = new Port(PortType.OUT, typeof(TimeSpan), AcceptsLinks.MULTIPLE, "Position");
        Port ready = new Port(PortType.OUT, typeof(RUN), AcceptsLinks.MULTIPLE, "Ready");
        Port ended = new Port(PortType.OUT, typeof(RUN), AcceptsLinks.MULTIPLE, "Ended");
        Variable var1 = new Variable("System.Windows.Media.MediaPlayer", string.Empty, "new System.Windows.Media.MediaPlayer()");
        public AudioPlayer()
        {
            Name = "Audio Player";
            AddPort(play);
            AddPort(pause);
            AddPort(stop);
            AddPort(file);
            AddPort(vol);
            AddPort(speed);
            AddPort(trackbar);
            AddPort(ready);
            AddPort(ended);
            AddPort(length);
            AddPort(position);
            Variables.Add(var1);
            Information = "Plays the specified sound file. " +
               "Select a sound file and call 'Play', you can also Stop or Pause by calling 'Stop' or 'Pause'.";
        }
        public override void UpdateResults()
        {
            var1.Name = this.ID;
            string tb = GetValue(trackbar);
            string trackinit = this.ID + ".MediaEnded += delegate (object os, EventArgs ea) { " + GetValue(ended) + " };\r\n";
            if (trackbar.IsConnected)
            {
                trackinit += @"System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
            t.Interval = 100;
            t.Enabled = true;
            t.Start();
            t.Tick += delegate(object os, EventArgs ea) {if (" + this.ID + ".Position.TotalSeconds <= tbr.maximum)="" {"="" +="" getvalue(trackbar)="" +="" ".value="Convert.ToInt32("" +="" this.id="" +="" ".position.totalseconds);}};\r\n";="" trackinit="" +="this.ID" +="" ".mediaopened+="delegate(object" os,="" eventargs="" ea){if("="" +="" this.id="" +="" ".naturalduration.hastimespan){tbr.maximum="Convert.ToInt32("" +="" this.id="" +="" ".naturalduration.timespan.totalseconds);="" "="" +="" getvalue(ready)="" +="" "}};\r\n";="" trackinit="" +="TBR.Scroll += delegate(object os, EventArgs ea){" +="" this.id="" +="" ".position="new" timespan(0,="" 0,="" tbr.value);};\r\n";="" trackinit="trackinit.Replace("TBR"," tb);="" }="" play.instructions="this.ID" +="" ".open(new="" uri("="" +="" getvalue(file)="" +="" "));="" \r\n"="" +="" trackinit="" +="" "="" "="" +="" this.id="" +="" ".play();";="" pause.instructions="this.ID" +="" ".pause();";="" stop.instructions="this.ID" +="" ".stop();";="" vol.instructions="this.ID" +="" ".volume";="" speed.instructions="this.ID" +="" ".speedratio";="" length.instructions="this.ID" +="" ".naturalduration.timespan";="" position.instructions="this.ID" +="" ".position";="" }="" }="" }=""></=>