123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- //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<string> 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);
- }
- }
- }
|