added ability to deal with mp3+g zip files

Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
Matt Bruce 2016-03-21 23:33:17 -05:00
parent be8f8a328e
commit e913f609bc
6 changed files with 103 additions and 28 deletions

View File

@ -3,10 +3,9 @@
<configSections> <configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<connectionStrings> <connectionStrings>
<add providerName="System.Data.SqlClient" <add providerName="System.Data.SqlClient" connectionString="Data Source=tcp:herse.database.windows.net,1433;Initial Catalog=herse;Persist Security Info=True;User ID=herse;password=94diablo!" name="HerseDb" />
connectionString="Data Source=tcp:herse.database.windows.net,1433;Initial Catalog=herse;Persist Security Info=True;User ID=herse;password=94diablo!" name="HerseDb"/>
</connectionStrings> </connectionStrings>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />

View File

@ -34,14 +34,24 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MaterialSkin, Version=0.0.3.3, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="MaterialSkin, Version=0.0.3.3, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>lib\MaterialSkin.dll</HintPath> <HintPath>lib\MaterialSkin.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing.Design" /> <Reference Include="System.Drawing.Design" />
<Reference Include="System.IO.Compression" /> <Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
@ -51,6 +61,10 @@
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="taglib-sharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=db62eba44689b5b0, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\taglib-sharp.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="MainForm.cs"> <Compile Include="MainForm.cs">
@ -91,6 +105,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="lib\MaterialSkin.dll" /> <Content Include="lib\MaterialSkin.dll" />
<Content Include="lib\taglib-sharp.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="lib\vlc\libvlc.dll" /> <Content Include="lib\vlc\libvlc.dll" />
<Content Include="lib\vlc\libvlccore.dll" /> <Content Include="lib\vlc\libvlccore.dll" />
<Content Include="lib\vlc\plugins\access\libaccess_attachment_plugin.dll" /> <Content Include="lib\vlc\plugins\access\libaccess_attachment_plugin.dll" />

View File

@ -34,13 +34,13 @@
this.btnBrowse = new MaterialSkin.Controls.MaterialRaisedButton(); this.btnBrowse = new MaterialSkin.Controls.MaterialRaisedButton();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.btnStop = new MaterialSkin.Controls.MaterialRaisedButton();
this.btnPlayQueue = new MaterialSkin.Controls.MaterialRaisedButton(); this.btnPlayQueue = new MaterialSkin.Controls.MaterialRaisedButton();
this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.materialListBox1 = new MaterialSkin.Controls.MaterialListBox(); this.materialListBox1 = new MaterialSkin.Controls.MaterialListBox();
this.materialSingleLineTextField1 = new MaterialSkin.Controls.MaterialSingleLineTextField(); this.materialSingleLineTextField1 = new MaterialSkin.Controls.MaterialSingleLineTextField();
this.browseDialog = new System.Windows.Forms.FolderBrowserDialog(); this.browseDialog = new System.Windows.Forms.FolderBrowserDialog();
this.btnStop = new MaterialSkin.Controls.MaterialRaisedButton();
this.tableLayoutPanel1.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout();
this.flowLayoutPanel1.SuspendLayout(); this.flowLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
@ -128,6 +128,19 @@
this.flowLayoutPanel1.Size = new System.Drawing.Size(713, 43); this.flowLayoutPanel1.Size = new System.Drawing.Size(713, 43);
this.flowLayoutPanel1.TabIndex = 6; this.flowLayoutPanel1.TabIndex = 6;
// //
// btnStop
//
this.btnStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnStop.Depth = 0;
this.btnStop.Location = new System.Drawing.Point(629, 3);
this.btnStop.MouseState = MaterialSkin.MouseState.HOVER;
this.btnStop.Name = "btnStop";
this.btnStop.Size = new System.Drawing.Size(81, 37);
this.btnStop.TabIndex = 4;
this.btnStop.Text = "Stop";
this.btnStop.UseVisualStyleBackColor = true;
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
//
// btnPlayQueue // btnPlayQueue
// //
this.btnPlayQueue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnPlayQueue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
@ -139,6 +152,7 @@
this.btnPlayQueue.TabIndex = 3; this.btnPlayQueue.TabIndex = 3;
this.btnPlayQueue.Text = "Play Queue"; this.btnPlayQueue.Text = "Play Queue";
this.btnPlayQueue.UseVisualStyleBackColor = true; this.btnPlayQueue.UseVisualStyleBackColor = true;
this.btnPlayQueue.Click += new System.EventHandler(this.btnPlayQueue_Click);
// //
// splitContainer1 // splitContainer1
// //
@ -215,19 +229,6 @@
this.materialSingleLineTextField1.UseSystemPasswordChar = false; this.materialSingleLineTextField1.UseSystemPasswordChar = false;
this.materialSingleLineTextField1.TextChanged += new System.EventHandler(this.materialSingleLineTextField1_TextChanged); this.materialSingleLineTextField1.TextChanged += new System.EventHandler(this.materialSingleLineTextField1_TextChanged);
// //
// btnStop
//
this.btnStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnStop.Depth = 0;
this.btnStop.Location = new System.Drawing.Point(629, 3);
this.btnStop.MouseState = MaterialSkin.MouseState.HOVER;
this.btnStop.Name = "btnStop";
this.btnStop.Size = new System.Drawing.Size(81, 37);
this.btnStop.TabIndex = 4;
this.btnStop.Text = "Stop";
this.btnStop.UseVisualStyleBackColor = true;
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
//
// MainForm // MainForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -6,14 +6,17 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Herse.Models; using Herse.Models;
using System.IO.Compression;
namespace KaraokePlayer namespace KaraokePlayer
{ {
public partial class MainForm : MaterialForm public partial class MainForm : MaterialForm
{ {
HerseDb db = new HerseDb();
private readonly MaterialSkinManager _materialSkinManager; private readonly MaterialSkinManager _materialSkinManager;
private List<Song> _fileList; private List<Song> _fileList;
private Song currentSong = null; private Song currentSong = null;
private KaraokeVideoPlayer currentPlayer = null;
public MainForm() public MainForm()
{ {
InitializeComponent(); InitializeComponent();
@ -37,12 +40,12 @@ namespace KaraokePlayer
{ {
if (browseDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) if (browseDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{ {
var files = GetFiles(browseDialog.SelectedPath, "*.cdg|*.mp4", searchOption: System.IO.SearchOption.AllDirectories); var files = GetFiles(browseDialog.SelectedPath, "*.cdg|*.mp4|*.zip", searchOption: System.IO.SearchOption.AllDirectories);
var filtered = files.Where(f => f.Length < 248).ToList(); var filtered = files.Where(f => f.Length < 248).ToList();
_fileList = filtered.Select(file => new Song(file)).ToList(); _fileList = filtered.Select(file => CreateSongForPath(file)).ToList();
materialListBox1.DataSource = _fileList; materialListBox1.DataSource = _fileList;
materialListBox1.DisplayMember = "FileName"; materialListBox1.DisplayMember = "Description";
} }
} }
@ -78,12 +81,40 @@ namespace KaraokePlayer
currentSong = file; currentSong = file;
if (file.Extension.ToLower() == "cdg") if (file.Extension.ToLower() == "cdg")
{ {
karaokeCDGPlayer.Play(new Uri(Path.ChangeExtension(file.FullPath, ".mp3"))); currentPlayer = karaokeCDGPlayer;
karaokeCDGPlayer.Play(new Uri(Path.ChangeExtension(file.FullPath, ".mp3")));
karaokeCDGPlayer.Visible = true; karaokeCDGPlayer.Visible = true;
karaokeMP4Player.Visible = false; karaokeMP4Player.Visible = false;
karaokeMP4Player.Stop(); karaokeMP4Player.Stop();
} }
else if (file.Extension.ToLower() == "zip")
{
string playPath = null;
string extractPath = Path.Combine(Directory.GetCurrentDirectory(), "temp");
DeleteDirectory(extractPath);
Directory.CreateDirectory(extractPath);
using (ZipArchive archive = ZipFile.OpenRead(file.FullPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.FullName.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase))
{
playPath = Path.Combine(extractPath, entry.FullName);
}
entry.ExtractToFile(Path.Combine(extractPath, entry.FullName));
}
}
if (!string.IsNullOrEmpty(playPath))
{
currentPlayer = karaokeCDGPlayer;
karaokeCDGPlayer.Play(new Uri(playPath));
karaokeCDGPlayer.Visible = true;
karaokeMP4Player.Visible = false;
karaokeMP4Player.Stop();
}
}
else { else {
currentPlayer = karaokeMP4Player;
karaokeMP4Player.Play(new Uri(file.FullPath)); karaokeMP4Player.Play(new Uri(file.FullPath));
karaokeMP4Player.Visible = true; karaokeMP4Player.Visible = true;
karaokeCDGPlayer.Visible = false; karaokeCDGPlayer.Visible = false;
@ -98,15 +129,41 @@ namespace KaraokePlayer
private void btnStop_Click(object sender, EventArgs e) private void btnStop_Click(object sender, EventArgs e)
{ {
if (currentSong == null) return; if (currentPlayer == null) return;
currentPlayer.Stop();
}
if (currentSong.Extension.ToLower() == "cdg") private Song CreateSongForPath(string path)
{
Song song = new Song(path);
return song;
}
public void DeleteDirectory(string target_dir)
{
if (!Directory.Exists(target_dir)) { return; }
string[] files = Directory.GetFiles(target_dir);
string[] dirs = Directory.GetDirectories(target_dir);
foreach (string file in files)
{ {
karaokeMP4Player.Stop(); File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);
} }
else {
karaokeCDGPlayer.Stop(); foreach (string dir in dirs)
{
DeleteDirectory(dir);
} }
Directory.Delete(target_dir, false);
}
private void btnPlayQueue_Click(object sender, EventArgs e)
{
_fileList = db.Songs.Where(s => s.Id > 0).OrderBy(s=>s.Artist).ThenBy(s=>s.Title).ToList();
materialListBox1.DataSource = _fileList;
materialListBox1.DisplayMember = "Description";
} }
} }
} }

Binary file not shown.

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net46" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net46" /> <package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net46" />
<package id="Microsoft.Bcl.Compression" version="3.9.85" targetFramework="net46" /> <package id="Microsoft.Bcl.Compression" version="3.9.85" targetFramework="net46" />
</packages> </packages>