private void CheckForBroadcast()
 {
     int i = 0;
     int waitingCount = 0;
     while ((!backgroundWorker1.CancellationPending) && (i < channels.Count) && (!channelLoading))
     {
         if (!channelLoading)
         {
             selectedChannel = channels[i];
             if (selectedChannel.BroadcastingChecked || selectedChannel.IsBroadcasting)
             {
                 //Log("Skipping channel (broadcasting already checked): " + selectedChannel.Name);
             }
             else
             {
                 StatusMessage.Text = "Checking channel for at least an audio stream: " + selectedChannel.Name;
                 backgroundWorker1.ReportProgress((100 * (i + 1)) / channelList.Items.Count);
                 TuneToChannel(selectedChannel);
                 if (vlcControl1.Media != null) vlcControl1.Media.Dispose();
                 vlcControl1.Media = new PathMedia(string.Format("rtp://@{0}", GetLocalIP() + ":500" + tuner));
                 vlcControl1.Play();
                 waitingCount = 0;
             }
             selectedChannel.BroadcastingChecked = true;
             i++;
         }
         else
         {
             Thread.Sleep(1000);
             waitingCount++;
             if (waitingCount > 5)
                 channelLoading = false;
         }
     }
 }
 private void addAChannelToolStripMenuItem_Click(object sender, EventArgs e)
 {
     DialogResult dr = new DialogResult();
     AddChannelDlg addChannelDlg = new AddChannelDlg();
     dr = addChannelDlg.ShowDialog();
     if (dr == DialogResult.OK)
     {
         if (device == "")
         {
             device = device_tb.Text;
         }
         if (tuner == "")
         {
             tuner = tuner_cb.Text;
         }
         Channel c = new Channel(addChannelDlg.Number, device, tuner);
         c.Callsign = addChannelDlg.Callsign;
         c.Name = addChannelDlg.Name;
         c.ProxyProgram = addChannelDlg.Proxy;
         c.VirtualNumber = addChannelDlg.VirtualNumber;
         channels.Add(c);
         RenderChannelList();
         CacheChannels();
     }
 }
 private void channelList_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         ListViewItem item = channelList.SelectedItems[0];
         if (item == null)
             return;
         selectedChannel = (Channel)item.Tag;
     } catch (Exception ex) { }
 }
        public void TuneToChannel(Channel channel, bool popup = false)
        {
            Log("Tuning to channel: " + channel.VirtualNumber + " - " + channel.Name);

            channelLoading = true;

            ProcessStartInfo tune = new ProcessStartInfo();
            tune.FileName = settings.HDHRPath;
            tune.UseShellExecute = false;
            tune.RedirectStandardOutput = true;
            tune.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            tune.CreateNoWindow = true;

            //hdhomerun_config FFFFFFFF set /tuner0/channel none
            string[] args = { device, "set", "/tuner" + tuner + "/channel", "none" };
            tune.Arguments = String.Join(" ", args);
            //Log("  exec: \"" + settings.HDHRPath + "\" " + tune.Arguments);
            using (Process process = Process.Start(tune))
            {
                using (StreamReader reader = process.StandardOutput)
                {
                    string result = "";
                    while ((result = reader.ReadLine()) != null)
                    {
                        Log(result);
                    }
                }
            }

            //hdhomerun_config FFFFFFFF set /tuner0/channel none
            string[] args3 = { device, "set", "/tuner" + tuner + "/channel", "auto:" + channel.Number };
            tune.Arguments = String.Join(" ", args3);
            Log("  exec: \"" + settings.HDHRPath + "\" " + tune.Arguments);
            using (Process process3 = Process.Start(tune))
            {
                using (StreamReader reader = process3.StandardOutput)
                {
                    string result = "";
                    while ((result = reader.ReadLine()) != null)
                    {
                        Log(result);
                    }
                }
            }

            //hdhomerun_config FFFFFFFF set /tuner0/channel none
            string[] args2 = { device, "set", "/tuner" + tuner + "/program", channel.ProxyProgram };
            tune.Arguments = String.Join(" ", args2);
            Log("  exec: \"" + settings.HDHRPath + "\" " + tune.Arguments);
            using (Process process2 = Process.Start(tune))
            {
                using (StreamReader reader = process2.StandardOutput)
                {
                    string result = "";
                    while ((result = reader.ReadLine()) != null)
                    {
                        Log(result);
                    }
                }
            }

            ///tuner0/target rtp://192.168.1.6:5000
            string[] args4 = { device, "set", "/tuner" + tuner + "/target", "rtp://" + GetLocalIP() + ":500" + tuner };
            tune.Arguments = String.Join(" ", args4);
            //Log("  exec: \"" + settings.HDHRPath + "\" " + tune.Arguments);
            using (Process process4 = Process.Start(tune))
            {
                using (StreamReader reader = process4.StandardOutput)
                {
                    string result = "";
                    while ((result = reader.ReadLine()) != null)
                    {
                        Log(result);
                    }
                }
            }

            if (popup)
            {
                ProcessStartInfo vlc = new ProcessStartInfo();
                if (System.IO.Directory.Exists(CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_AMD64))
                    vlc.FileName = CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_AMD64 + "vlc.exe";
                else
                    vlc.FileName = CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_X86 + "vlc.exe";
                tune.UseShellExecute = false;
                tune.RedirectStandardOutput = true;
                string[] args5 = { "-vvv", "rtp://" + GetLocalIP() + ":500" + tuner };
                vlc.Arguments = String.Join(" ", args5);
                //Log("  exec: \"" + vlc.FileName + "\" " + vlc.Arguments);
                Process process = Process.Start(vlc);
            }
        }