Audio Player work.

This commit is contained in:
Michael 2017-04-24 21:01:42 -04:00
parent 7c070a8213
commit d4316e75fc
8 changed files with 477 additions and 10 deletions

View file

@ -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;
}
}

View file

@ -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;
}
}
}
}

View file

@ -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>

View file

@ -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,

View file

@ -38,6 +38,10 @@
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="NAudio, Version=1.8.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.8.0\lib\net35\NAudio.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
@ -374,6 +378,9 @@
<EmbeddedResource Include="Applications\Artpad.resx">
<DependentUpon>Artpad.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Applications\AudioPlayer.resx">
<DependentUpon>AudioPlayer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Applications\Calculator.resx">
<DependentUpon>Calculator.cs</DependentUpon>
</EmbeddedResource>
@ -746,6 +753,25 @@
<None Include="Resources\secretlang.txt" />
<None Include="Resources\strings_ver.txt" />
</ItemGroup>
<ItemGroup>
<COMReference Include="AxWMPLib">
<Guid>{6BF52A50-394A-11D3-B153-00C04F79FAA6}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>aximp</WrapperTool>
<Isolated>False</Isolated>
</COMReference>
<COMReference Include="WMPLib">
<Guid>{6BF52A50-394A-11D3-B153-00C04F79FAA6}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View file

@ -354,7 +354,7 @@ namespace ShiftOS.WinForms
/// </summary>
public class AppscapeEntryAttribute : RequiresUpgradeAttribute
{
public AppscapeEntryAttribute(string name, string description, int downloadSize, long cost, string dependencies = "", string category = "Misc") : base((string.IsNullOrWhiteSpace(dependencies)) ? name.ToLower().Replace(" ", "_") : name.ToLower().Replace(" ", "_") + dependencies)
public AppscapeEntryAttribute(string name, string description, int downloadSize, long cost, string dependencies = "", string category = "Misc") : base(name.ToLower().Replace(' ', '_'))
{
Name = name;
Description = description;

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommonMark.NET" version="0.15.0" targetFramework="net451" />
<package id="NAudio" version="1.8.0" targetFramework="net451" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net451" />
<package id="Vlc.DotNet.Core.Interops" version="2.1.130" targetFramework="net451" />
</packages>

View file

@ -248,6 +248,16 @@ namespace ShiftOS.Engine
if (SaveSystem.CurrentSave.StoriesExperienced == null)
SaveSystem.CurrentSave.StoriesExperienced = new List<string>();
if (id.Contains(';'))
{
foreach(var u in id.Split(';'))
{
if (UpgradeInstalled(u) == false)
return false;
}
return true;
}
bool upgInstalled = false;
if(SaveSystem.CurrentSave.Upgrades.ContainsKey(id))
upgInstalled = SaveSystem.CurrentSave.Upgrades[id];