Added controls panel and playing of music

This commit is contained in:
2015-10-29 20:12:59 +01:00
parent 23a7373338
commit a45d506dbc
4 changed files with 97 additions and 9 deletions
+39 -5
View File
@@ -37,6 +37,9 @@
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.playToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ControlsPanel = new System.Windows.Forms.Panel();
((System.ComponentModel.ISupportInitialize)(this.SongsTableView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.SongsTableView)).BeginInit();
this.MainPanel.SuspendLayout(); this.MainPanel.SuspendLayout();
this.MenuStrip.SuspendLayout(); this.MenuStrip.SuspendLayout();
@@ -58,7 +61,7 @@
this.SongsTableView.ReadOnly = true; this.SongsTableView.ReadOnly = true;
this.SongsTableView.RowHeadersVisible = false; this.SongsTableView.RowHeadersVisible = false;
this.SongsTableView.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.SongsTableView.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.SongsTableView.Size = new System.Drawing.Size(760, 172); this.SongsTableView.Size = new System.Drawing.Size(760, 148);
this.SongsTableView.TabIndex = 0; this.SongsTableView.TabIndex = 0;
// //
// GenreListBox // GenreListBox
@@ -92,20 +95,23 @@
// //
// MainPanel // MainPanel
// //
this.MainPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.MainPanel.Controls.Add(this.GenreListBox); this.MainPanel.Controls.Add(this.GenreListBox);
this.MainPanel.Controls.Add(this.ArtistListBox); this.MainPanel.Controls.Add(this.ArtistListBox);
this.MainPanel.Controls.Add(this.AlbumListView); this.MainPanel.Controls.Add(this.AlbumListView);
this.MainPanel.Controls.Add(this.SongsTableView); this.MainPanel.Controls.Add(this.SongsTableView);
this.MainPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.MainPanel.Location = new System.Drawing.Point(0, 24); this.MainPanel.Location = new System.Drawing.Point(0, 24);
this.MainPanel.Name = "MainPanel"; this.MainPanel.Name = "MainPanel";
this.MainPanel.Size = new System.Drawing.Size(784, 337); this.MainPanel.Size = new System.Drawing.Size(784, 313);
this.MainPanel.TabIndex = 5; this.MainPanel.TabIndex = 5;
// //
// MenuStrip // MenuStrip
// //
this.MenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.MenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem}); this.fileToolStripMenuItem,
this.viewToolStripMenuItem});
this.MenuStrip.Location = new System.Drawing.Point(0, 0); this.MenuStrip.Location = new System.Drawing.Point(0, 0);
this.MenuStrip.Name = "MenuStrip"; this.MenuStrip.Name = "MenuStrip";
this.MenuStrip.Size = new System.Drawing.Size(784, 24); this.MenuStrip.Size = new System.Drawing.Size(784, 24);
@@ -133,11 +139,36 @@
this.saveToolStripMenuItem.Size = new System.Drawing.Size(103, 22); this.saveToolStripMenuItem.Size = new System.Drawing.Size(103, 22);
this.saveToolStripMenuItem.Text = "Save"; this.saveToolStripMenuItem.Text = "Save";
// //
// viewToolStripMenuItem
//
this.viewToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.playToolStripMenuItem});
this.viewToolStripMenuItem.Name = "viewToolStripMenuItem";
this.viewToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
this.viewToolStripMenuItem.Text = "View";
//
// playToolStripMenuItem
//
this.playToolStripMenuItem.Name = "playToolStripMenuItem";
this.playToolStripMenuItem.Size = new System.Drawing.Size(96, 22);
this.playToolStripMenuItem.Text = "Play";
this.playToolStripMenuItem.Click += new System.EventHandler(this.playToolStripMenuItem_Click);
//
// ControlsPanel
//
this.ControlsPanel.BackColor = System.Drawing.SystemColors.HotTrack;
this.ControlsPanel.Dock = System.Windows.Forms.DockStyle.Bottom;
this.ControlsPanel.Location = new System.Drawing.Point(0, 343);
this.ControlsPanel.Name = "ControlsPanel";
this.ControlsPanel.Size = new System.Drawing.Size(784, 119);
this.ControlsPanel.TabIndex = 4;
//
// MainForm // MainForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(784, 361); this.ClientSize = new System.Drawing.Size(784, 462);
this.Controls.Add(this.ControlsPanel);
this.Controls.Add(this.MainPanel); this.Controls.Add(this.MainPanel);
this.Controls.Add(this.MenuStrip); this.Controls.Add(this.MenuStrip);
this.MainMenuStrip = this.MenuStrip; this.MainMenuStrip = this.MenuStrip;
@@ -164,6 +195,9 @@
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem viewToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem playToolStripMenuItem;
private System.Windows.Forms.Panel ControlsPanel;
} }
} }
+49 -1
View File
@@ -1,10 +1,14 @@
using System; using NAudio.Wave;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.IO;
using System.Linq; using System.Linq;
using System.Net;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@@ -50,5 +54,49 @@ namespace MusicPlayer
table.Add(new Song("Test Song 2", "Test Album 2", "Test Artist 2")); table.Add(new Song("Test Song 2", "Test Album 2", "Test Artist 2"));
} }
private void playToolStripMenuItem_Click(object sender, EventArgs e)
{
PlayMp3FromUrl("http://imegumii.nl/music/English/Monstercat/Direct%20-%20Eternity.mp3");
}
private Stream ms = new MemoryStream();
public void PlayMp3FromUrl(string url)
{
new Thread(delegate (object o)
{
var response = WebRequest.Create(url).GetResponse();
using (var stream = response.GetResponseStream())
{
byte[] buffer = new byte[65536]; // 64KB chunks
int read;
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
{
var pos = ms.Position;
ms.Position = ms.Length;
ms.Write(buffer, 0, read);
ms.Position = pos;
}
}
}).Start();
// Pre-buffering some data to allow NAudio to start playing
while (ms.Length < 65536 * 10)
Thread.Sleep(1000);
ms.Position = 0;
using (WaveStream blockAlignedStream = new BlockAlignReductionStream(WaveFormatConversionStream.CreatePcmStream(new Mp3FileReader(ms))))
{
using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
{
waveOut.Init(blockAlignedStream);
waveOut.Play();
while (waveOut.PlaybackState == PlaybackState.Playing)
{
System.Threading.Thread.Sleep(100);
}
}
}
}
} }
} }
+7 -2
View File
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
@@ -33,6 +33,10 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="NAudio, Version=1.7.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.7.3\lib\net35\NAudio.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
@@ -46,7 +50,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="MainForm.cs" > <Compile Include="MainForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="Album.cs" /> <Compile Include="Album.cs" />
@@ -74,6 +78,7 @@
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+1
View File
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="NAudio" version="1.7.3" targetFramework="net452" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" /> <package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" />
</packages> </packages>