Program.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //Target:Winform
  2. using System;
  3. using System.Drawing;
  4. using System.Media;
  5. using System.Reflection;
  6. using System.Windows.Forms;
  7. [assembly: AssemblyTitle("LoopPlayAudio")]
  8. [assembly: AssemblyProduct("LoopPlayAudio")]
  9. namespace LoopPlayAudio
  10. {
  11. internal static class Program
  12. {
  13. [STAThread]
  14. private static void Main(string[] args)
  15. {
  16. Application.EnableVisualStyles();
  17. Application.SetCompatibleTextRenderingDefault(false);
  18. var player = new SoundPlayer();
  19. var mainForm = new Form();
  20. var label = new Label();
  21. var statusBar = new StatusStrip();
  22. var statusLabel = new ToolStripStatusLabel();
  23. mainForm.Controls.Add(label);
  24. mainForm.Controls.Add(statusBar);
  25. statusBar.Items.Add(statusLabel);
  26. mainForm.ClientSize = new Size(640, mainForm.Font.Height + statusBar.Height);
  27. mainForm.MaximizeBox = false;
  28. mainForm.FormBorderStyle = FormBorderStyle.Sizable;
  29. mainForm.SizeGripStyle = SizeGripStyle.Show;
  30. mainForm.Text = Application.ProductName;
  31. label.Dock = DockStyle.Fill;
  32. label.Text = "Drop a file in to me to play looping...";
  33. statusLabel.Text = "Ready";
  34. Action<string> loopPlay = delegate (string file)
  35. {
  36. player.Stop();
  37. try
  38. {
  39. player.SoundLocation = file;
  40. player.PlayLooping();
  41. label.Text = file;
  42. statusLabel.Text = "Playing";
  43. }
  44. catch (Exception ex)
  45. {
  46. label.Text = "ERROR:" + ex.Message + Environment.NewLine + ex;
  47. statusLabel.Text = "Stopped";
  48. }
  49. };
  50. mainForm.AllowDrop = true;
  51. mainForm.DragEnter += delegate (object sender, DragEventArgs eventArgs) { eventArgs.Effect = DragDropEffects.Link; };
  52. mainForm.DragDrop += delegate (object sender, DragEventArgs eventArgs) { loopPlay(((string[])eventArgs.Data.GetData(DataFormats.FileDrop))[0]); };
  53. if (args.Length == 1) loopPlay(args[0]);
  54. Application.Run(mainForm);
  55. }
  56. }
  57. }