//Target:Winform using System; using System.Drawing; using System.Media; using System.Reflection; using System.Windows.Forms; [assembly: AssemblyTitle("LoopPlayAudio")] [assembly: AssemblyProduct("LoopPlayAudio")] namespace LoopPlayAudio { internal static class Program { [STAThread] private static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var player = new SoundPlayer(); var mainForm = new Form(); var label = new Label(); var statusBar = new StatusStrip(); var statusLabel = new ToolStripStatusLabel(); mainForm.Controls.Add(label); mainForm.Controls.Add(statusBar); statusBar.Items.Add(statusLabel); mainForm.ClientSize = new Size(640, mainForm.Font.Height + statusBar.Height); mainForm.MaximizeBox = false; mainForm.FormBorderStyle = FormBorderStyle.Sizable; mainForm.SizeGripStyle = SizeGripStyle.Show; mainForm.Text = Application.ProductName; label.Dock = DockStyle.Fill; label.Text = "Drop a file in to me to play looping..."; statusLabel.Text = "Ready"; Action loopPlay = delegate (string file) { player.Stop(); try { player.SoundLocation = file; player.PlayLooping(); label.Text = file; statusLabel.Text = "Playing"; } catch (Exception ex) { label.Text = "ERROR:" + ex.Message + Environment.NewLine + ex; statusLabel.Text = "Stopped"; } }; mainForm.AllowDrop = true; mainForm.DragEnter += delegate (object sender, DragEventArgs eventArgs) { eventArgs.Effect = DragDropEffects.Link; }; mainForm.DragDrop += delegate (object sender, DragEventArgs eventArgs) { loopPlay(((string[])eventArgs.Data.GetData(DataFormats.FileDrop))[0]); }; if (args.Length == 1) loopPlay(args[0]); Application.Run(mainForm); } } }