diff --git a/ShiftOS.WinForms/Applications/AudioPlayer.Designer.cs b/ShiftOS.WinForms/Applications/AudioPlayer.Designer.cs index 83f41d2..825413d 100644 --- a/ShiftOS.WinForms/Applications/AudioPlayer.Designer.cs +++ b/ShiftOS.WinForms/Applications/AudioPlayer.Designer.cs @@ -52,10 +52,182 @@ namespace ShiftOS.WinForms.Applications /// private void InitializeComponent() { - components = new System.ComponentModel.Container(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AudioPlayer)); + this.wpaudio = new AxWMPLib.AxWindowsMediaPlayer(); + this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer(); + this.lbtracks = new System.Windows.Forms.ListBox(); + this.flcontrols = new System.Windows.Forms.FlowLayoutPanel(); + this.btnplay = new System.Windows.Forms.Button(); + this.pgplaytime = new ShiftOS.WinForms.Controls.ShiftedProgressBar(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.addSongToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.clearToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.shuffleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.removeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)(this.wpaudio)).BeginInit(); + this.toolStripContainer1.ContentPanel.SuspendLayout(); + this.toolStripContainer1.TopToolStripPanel.SuspendLayout(); + this.toolStripContainer1.SuspendLayout(); + this.flcontrols.SuspendLayout(); + this.menuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // wpaudio + // + this.wpaudio.Dock = System.Windows.Forms.DockStyle.Fill; + this.wpaudio.Enabled = true; + this.wpaudio.Location = new System.Drawing.Point(0, 0); + this.wpaudio.Name = "wpaudio"; + this.wpaudio.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("wpaudio.OcxState"))); + this.wpaudio.Size = new System.Drawing.Size(798, 471); + this.wpaudio.TabIndex = 0; + this.wpaudio.Visible = false; + // + // toolStripContainer1 + // + // + // toolStripContainer1.ContentPanel + // + this.toolStripContainer1.ContentPanel.Controls.Add(this.lbtracks); + this.toolStripContainer1.ContentPanel.Controls.Add(this.flcontrols); + this.toolStripContainer1.ContentPanel.Size = new System.Drawing.Size(798, 447); + this.toolStripContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + this.toolStripContainer1.LeftToolStripPanelVisible = false; + this.toolStripContainer1.Location = new System.Drawing.Point(0, 0); + this.toolStripContainer1.Name = "toolStripContainer1"; + this.toolStripContainer1.RightToolStripPanelVisible = false; + this.toolStripContainer1.Size = new System.Drawing.Size(798, 471); + this.toolStripContainer1.TabIndex = 1; + this.toolStripContainer1.Text = "toolStripContainer1"; + // + // toolStripContainer1.TopToolStripPanel + // + this.toolStripContainer1.TopToolStripPanel.Controls.Add(this.menuStrip1); + // + // lbtracks + // + this.lbtracks.Dock = System.Windows.Forms.DockStyle.Fill; + this.lbtracks.FormattingEnabled = true; + this.lbtracks.Location = new System.Drawing.Point(0, 0); + this.lbtracks.Name = "lbtracks"; + this.lbtracks.Size = new System.Drawing.Size(798, 418); + this.lbtracks.TabIndex = 1; + this.lbtracks.SelectedIndexChanged += new System.EventHandler(this.lbtracks_SelectedIndexChanged); + // + // flcontrols + // + this.flcontrols.AutoSize = true; + this.flcontrols.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.flcontrols.Controls.Add(this.btnplay); + this.flcontrols.Controls.Add(this.pgplaytime); + this.flcontrols.Dock = System.Windows.Forms.DockStyle.Bottom; + this.flcontrols.Location = new System.Drawing.Point(0, 418); + this.flcontrols.Name = "flcontrols"; + this.flcontrols.Size = new System.Drawing.Size(798, 29); + this.flcontrols.TabIndex = 0; + // + // btnplay + // + this.btnplay.AutoSize = true; + this.btnplay.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnplay.Location = new System.Drawing.Point(3, 3); + this.btnplay.Name = "btnplay"; + this.btnplay.Size = new System.Drawing.Size(37, 23); + this.btnplay.TabIndex = 0; + this.btnplay.Text = "Play"; + this.btnplay.UseVisualStyleBackColor = true; + this.btnplay.Click += new System.EventHandler(this.btnplay_Click); + // + // pgplaytime + // + this.pgplaytime.BlockSize = 5; + this.pgplaytime.Location = new System.Drawing.Point(46, 3); + this.pgplaytime.Maximum = 100; + this.pgplaytime.Name = "pgplaytime"; + this.pgplaytime.Size = new System.Drawing.Size(749, 23); + this.pgplaytime.Style = System.Windows.Forms.ProgressBarStyle.Continuous; + this.pgplaytime.TabIndex = 1; + this.pgplaytime.Tag = "keepbg"; + this.pgplaytime.Text = "shiftedProgressBar1"; + this.pgplaytime.Value = 0; + // + // menuStrip1 + // + this.menuStrip1.Dock = System.Windows.Forms.DockStyle.None; + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.addSongToolStripMenuItem, + this.clearToolStripMenuItem, + this.shuffleToolStripMenuItem, + this.removeToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(798, 24); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // addSongToolStripMenuItem + // + this.addSongToolStripMenuItem.Name = "addSongToolStripMenuItem"; + this.addSongToolStripMenuItem.Size = new System.Drawing.Size(71, 20); + this.addSongToolStripMenuItem.Text = "Add Song"; + this.addSongToolStripMenuItem.Click += new System.EventHandler(this.addSongToolStripMenuItem_Click); + // + // clearToolStripMenuItem + // + this.clearToolStripMenuItem.Name = "clearToolStripMenuItem"; + this.clearToolStripMenuItem.Size = new System.Drawing.Size(46, 20); + this.clearToolStripMenuItem.Text = "Clear"; + this.clearToolStripMenuItem.Click += new System.EventHandler(this.clearToolStripMenuItem_Click); + // + // shuffleToolStripMenuItem + // + this.shuffleToolStripMenuItem.Name = "shuffleToolStripMenuItem"; + this.shuffleToolStripMenuItem.Size = new System.Drawing.Size(56, 20); + this.shuffleToolStripMenuItem.Text = "Shuffle"; + this.shuffleToolStripMenuItem.Click += new System.EventHandler(this.shuffleToolStripMenuItem_Click); + // + // removeToolStripMenuItem + // + this.removeToolStripMenuItem.Name = "removeToolStripMenuItem"; + this.removeToolStripMenuItem.Size = new System.Drawing.Size(62, 20); + this.removeToolStripMenuItem.Text = "Remove"; + this.removeToolStripMenuItem.Click += new System.EventHandler(this.removeToolStripMenuItem_Click); + // + // AudioPlayer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.toolStripContainer1); + this.Controls.Add(this.wpaudio); + this.Name = "AudioPlayer"; + this.Size = new System.Drawing.Size(798, 471); + ((System.ComponentModel.ISupportInitialize)(this.wpaudio)).EndInit(); + this.toolStripContainer1.ContentPanel.ResumeLayout(false); + this.toolStripContainer1.ContentPanel.PerformLayout(); + this.toolStripContainer1.TopToolStripPanel.ResumeLayout(false); + this.toolStripContainer1.TopToolStripPanel.PerformLayout(); + this.toolStripContainer1.ResumeLayout(false); + this.toolStripContainer1.PerformLayout(); + this.flcontrols.ResumeLayout(false); + this.flcontrols.PerformLayout(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.ResumeLayout(false); + } #endregion + + private AxWMPLib.AxWindowsMediaPlayer wpaudio; + private System.Windows.Forms.ToolStripContainer toolStripContainer1; + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ToolStripMenuItem addSongToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem clearToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem shuffleToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem removeToolStripMenuItem; + private System.Windows.Forms.ListBox lbtracks; + private System.Windows.Forms.FlowLayoutPanel flcontrols; + private System.Windows.Forms.Button btnplay; + private Controls.ShiftedProgressBar pgplaytime; } } diff --git a/ShiftOS.WinForms/Applications/AudioPlayer.cs b/ShiftOS.WinForms/Applications/AudioPlayer.cs index b8be6af..6d4d58a 100644 --- a/ShiftOS.WinForms/Applications/AudioPlayer.cs +++ b/ShiftOS.WinForms/Applications/AudioPlayer.cs @@ -32,9 +32,15 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ShiftOS.Engine; +using NAudio; +using System.Threading; namespace ShiftOS.WinForms.Applications { + [AppscapeEntry("Audio Player", "Play music and other sounds on your computer.", 3047, 1000, "file_skimmer", "Entertainment")] + [Launcher("Audio Player", false, null, "Entertainment")] + [WinOpen("audio_player")] + [DefaultTitle("Audio Player")] public partial class AudioPlayer : UserControl, IShiftOSWindow { public AudioPlayer() @@ -42,9 +48,12 @@ namespace ShiftOS.WinForms.Applications InitializeComponent(); } + NAudio.Wave.WaveOut o = null; + + public void OnLoad() { - + wpaudio.Hide(); } public void OnSkinLoad() @@ -54,6 +63,9 @@ namespace ShiftOS.WinForms.Applications public bool OnUnload() { + o?.Dispose(); + mp3?.Dispose(); + memstream?.Dispose(); return true; } @@ -61,5 +73,124 @@ namespace ShiftOS.WinForms.Applications { } + + private void addSongToolStripMenuItem_Click(object sender, EventArgs e) + { + FileSkimmerBackend.GetFile(new[] { ".mp3", ".wav" }, FileOpenerStyle.Open, (path) => + { + if (!lbtracks.Items.Contains(path)) + lbtracks.Items.Add(path); + else + Infobox.Show("Song already added!", "That song is already added to the Audio Player playlist."); + }); + } + + private void clearToolStripMenuItem_Click(object sender, EventArgs e) + { + lbtracks.Items.Clear(); + } + + private void shuffleToolStripMenuItem_Click(object sender, EventArgs e) + { + var lst = new object[lbtracks.Items.Count]; + lbtracks.Items.CopyTo(lst, 0); + var shuffle = new List(lst); + shuffle.Shuffle(); + lbtracks.Items.Clear(); + lbtracks.Items.AddRange(shuffle.ToArray()); + } + + private void removeToolStripMenuItem_Click(object sender, EventArgs e) + { + lbtracks.Items.RemoveAt(lbtracks.SelectedIndex); + } + + private void btnplay_Click(object sender, EventArgs e) + { + if(o == null) + { + if (lbtracks.Items.Count > 0) + { + Play(lbtracks.Items[0].ToString()); + btnplay.Text = "Pause"; + } + else + Infobox.Show("Error", "No tracks to play! Please add a track to the playlist."); + } + else if(o.PlaybackState == NAudio.Wave.PlaybackState.Paused) + { + o.Resume(); + btnplay.Text = "Pause"; + } + else if(o.PlaybackState == NAudio.Wave.PlaybackState.Playing) + { + o.Pause(); + btnplay.Text = "Play"; + } + } + + System.IO.Stream memstream = null; + NAudio.Wave.Mp3FileReader mp3 = null; + + public void Play(string track) + { + if (o != null) + { + o.Dispose(); + mp3.Dispose(); + memstream.Dispose(); + } + var bytes = ShiftOS.Objects.ShiftFS.Utils.ReadAllBytes(track); + memstream = new System.IO.MemoryStream(bytes); + mp3 = new NAudio.Wave.Mp3FileReader(memstream); + o = new NAudio.Wave.WaveOut(); + o.Init(mp3); + o.Play(); + + pgplaytime.Value = 0; + pgplaytime.Maximum = (int)mp3.Length; + new Thread(() => + { + while(o.PlaybackState == NAudio.Wave.PlaybackState.Playing || o.PlaybackState == NAudio.Wave.PlaybackState.Paused) + { + long time = mp3.Position; + if(time != mp3.Position) + { + time = mp3.Position; + this.Invoke(new Action(() => + { + pgplaytime.Value = (int)time; + })); + } + } + }).Start(); + } + + private void lbtracks_SelectedIndexChanged(object sender, EventArgs e) + { + try + { + Play(lbtracks.SelectedItem.ToString()); + } + catch { } + } + } + + public static class ListExtensions + { + private static Random rng = new Random(); + + public static void Shuffle(this IList list) + { + int n = list.Count; + while (n > 1) + { + n--; + int k = rng.Next(n + 1); + T value = list[k]; + list[k] = list[n]; + list[n] = value; + } + } } } diff --git a/ShiftOS.WinForms/Applications/AudioPlayer.resx b/ShiftOS.WinForms/Applications/AudioPlayer.resx new file mode 100644 index 0000000..d484b91 --- /dev/null +++ b/ShiftOS.WinForms/Applications/AudioPlayer.resx @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w + LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACFTeXN0 + ZW0uV2luZG93cy5Gb3Jtcy5BeEhvc3QrU3RhdGUBAAAABERhdGEHAgIAAAAJAwAAAA8DAAAAtwAAAAIB + AAAAAQAAAAAAAAAAAAAAAKIAAAAAAwAACAAAAAAABQAAAAAAAADwPwMAAAAAAAUAAAAAAAAAAAAIAAIA + AAAAAAMAAQAAAAsA//8DAAAAAAALAP//CAACAAAAAAADADIAAAALAAAACAAKAAAAbgBvAG4AZQAAAAsA + AAALAAAACwD//wsA//8LAAAACAACAAAAAAAIAAIAAAAAAAgAAgAAAAAACAACAAAAAAALAAAAelIAAK4w + AAAL + + + + 17, 17 + + \ No newline at end of file diff --git a/ShiftOS.WinForms/Resources/Shiftorium.txt b/ShiftOS.WinForms/Resources/Shiftorium.txt index e68277c..79d4dd0 100644 --- a/ShiftOS.WinForms/Resources/Shiftorium.txt +++ b/ShiftOS.WinForms/Resources/Shiftorium.txt @@ -633,13 +633,6 @@ Category: "Enhancements", Dependencies: "mud_fundamentals;window_manager;pong_upgrade" }, - { - Name: "Audio Player", - Cost: 10000, - Description: "Want to listen to the greatest tunes? Well get this app asap!", - Category: "Applications", - Dependencies: "desktop;wm_free_placement" - }, { Name: "Audio Player AL", Cost: 150, diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index a8d1aaa..dac803d 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -38,6 +38,10 @@ True + + ..\packages\NAudio.1.8.0\lib\net35\NAudio.dll + True + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True @@ -374,6 +378,9 @@ Artpad.cs + + AudioPlayer.cs + Calculator.cs @@ -746,6 +753,25 @@ + + + {6BF52A50-394A-11D3-B153-00C04F79FAA6} + 1 + 0 + 0 + aximp + False + + + {6BF52A50-394A-11D3-B153-00C04F79FAA6} + 1 + 0 + 0 + tlbimp + False + True + +