aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms/Applications
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.WinForms/Applications')
-rw-r--r--ShiftOS.WinForms/Applications/AudioPlayer.Designer.cs174
-rw-r--r--ShiftOS.WinForms/Applications/AudioPlayer.cs133
-rw-r--r--ShiftOS.WinForms/Applications/AudioPlayer.resx134
3 files changed, 439 insertions, 2 deletions
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
/// </summary>
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<object>(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<T>(this IList<T> 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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <data name="wpaudio.OcxState" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>
+ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
+ LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACFTeXN0
+ ZW0uV2luZG93cy5Gb3Jtcy5BeEhvc3QrU3RhdGUBAAAABERhdGEHAgIAAAAJAwAAAA8DAAAAtwAAAAIB
+ AAAAAQAAAAAAAAAAAAAAAKIAAAAAAwAACAAAAAAABQAAAAAAAADwPwMAAAAAAAUAAAAAAAAAAAAIAAIA
+ AAAAAAMAAQAAAAsA//8DAAAAAAALAP//CAACAAAAAAADADIAAAALAAAACAAKAAAAbgBvAG4AZQAAAAsA
+ AAALAAAACwD//wsA//8LAAAACAACAAAAAAAIAAIAAAAAAAgAAgAAAAAACAACAAAAAAALAAAAelIAAK4w
+ AAAL
+</value>
+ </data>
+ <metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+ <value>17, 17</value>
+ </metadata>
+</root> \ No newline at end of file