Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>

This commit is contained in:
Matt Bruce 2016-03-16 21:42:13 -05:00
parent 7c3f834786
commit 54c595809e
4 changed files with 85 additions and 43 deletions

View File

@ -2,6 +2,7 @@
{ {
partial class KaraokeVideoPlayer partial class KaraokeVideoPlayer
{ {
public bool isCDG { get; set; }
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
/// </summary> /// </summary>
@ -43,12 +44,12 @@
this.vlcPlayer.TabIndex = 0; this.vlcPlayer.TabIndex = 0;
this.vlcPlayer.Text = "vlcControl1"; this.vlcPlayer.Text = "vlcControl1";
this.vlcPlayer.VlcLibDirectory = null; this.vlcPlayer.VlcLibDirectory = null;
this.vlcPlayer.VlcMediaplayerOptions = new string[] { if (isCDG) {
"--projectm-preset-path=lib\\presets", this.vlcPlayer.VlcMediaplayerOptions = new string[] { "--projectm-preset-path=lib\\presets", "--audio-visual=projectm", "--effect-list=scope", "--no-video", "--verbose=2" };
"--audio-visual=projectm", }
"--effect-list=scope", else {
"--no-video", this.vlcPlayer.VlcMediaplayerOptions = new string[] { "--projectm-preset-path=lib\\presets", "--effect-list=scope", "--verbose=2" };
"--verbose=2"}; }
this.vlcPlayer.VlcLibDirectoryNeeded += new System.EventHandler<Vlc.DotNet.Forms.VlcLibDirectoryNeededEventArgs>(this.vlcPlayer_VlcLibDirectoryNeeded); this.vlcPlayer.VlcLibDirectoryNeeded += new System.EventHandler<Vlc.DotNet.Forms.VlcLibDirectoryNeededEventArgs>(this.vlcPlayer_VlcLibDirectoryNeeded);
this.vlcPlayer.Playing += new System.EventHandler<Vlc.DotNet.Core.VlcMediaPlayerPlayingEventArgs>(this.vlcPlayer_Playing); this.vlcPlayer.Playing += new System.EventHandler<Vlc.DotNet.Core.VlcMediaPlayerPlayingEventArgs>(this.vlcPlayer_Playing);
this.vlcPlayer.TimeChanged += new System.EventHandler<Vlc.DotNet.Core.VlcMediaPlayerTimeChangedEventArgs>(this.vlcPlayer_TimeChanged); this.vlcPlayer.TimeChanged += new System.EventHandler<Vlc.DotNet.Core.VlcMediaPlayerTimeChangedEventArgs>(this.vlcPlayer_TimeChanged);

View File

@ -29,14 +29,20 @@ namespace KaraokePlayer
private void LyricTimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs) private void LyricTimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
{ {
var picture = _cdgFile.RenderAtTime((long)(DateTime.Now - _startTime).TotalMilliseconds); if (isCDG)
BeginInvoke(new MethodInvoker(() => { _overlayForm.Graphic.Image = picture; })); {
var picture = _cdgFile.RenderAtTime((long)(DateTime.Now - _startTime).TotalMilliseconds);
BeginInvoke(new MethodInvoker(() => { _overlayForm.Graphic.Image = picture; }));
}
} }
public async void Play(Uri file) public async void Play(Uri file)
{ {
vlcPlayer.SetMedia(file); vlcPlayer.SetMedia(file);
_cdgFile = await GraphicsFile.LoadAsync(Path.ChangeExtension(file.LocalPath, "cdg")); if (isCDG)
{
_cdgFile = await GraphicsFile.LoadAsync(Path.ChangeExtension(file.LocalPath, "cdg"));
}
vlcPlayer.Play(); vlcPlayer.Play();
} }

View File

@ -33,11 +33,12 @@
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.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.browseDialog = new System.Windows.Forms.FolderBrowserDialog(); this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.karaokeVideoPlayer1 = new KaraokePlayer.KaraokeVideoPlayer();
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.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.karaokeCDGPlayer = new KaraokePlayer.KaraokeVideoPlayer();
this.karaokeMP4Player = new KaraokePlayer.KaraokeVideoPlayer();
this.browseDialog = new System.Windows.Forms.FolderBrowserDialog();
this.tableLayoutPanel1.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout();
this.flowLayoutPanel1.SuspendLayout(); this.flowLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
@ -117,22 +118,27 @@
// //
// splitContainer1.Panel2 // splitContainer1.Panel2
// //
this.splitContainer1.Panel2.Controls.Add(this.karaokeVideoPlayer1); this.splitContainer1.Panel2.Controls.Add(this.karaokeCDGPlayer);
this.splitContainer1.Panel2.Controls.Add(this.karaokeMP4Player);
this.splitContainer1.Size = new System.Drawing.Size(713, 458); this.splitContainer1.Size = new System.Drawing.Size(713, 458);
this.splitContainer1.SplitterDistance = 237; this.splitContainer1.SplitterDistance = 237;
this.splitContainer1.TabIndex = 6; this.splitContainer1.TabIndex = 6;
// //
// browseDialog // tableLayoutPanel2
// //
this.browseDialog.SelectedPath = "D:\\Karaoke\\SF360 February 2016\\SF360-01 - Charlie Puth - One Call Away\\"; this.tableLayoutPanel2.BackColor = System.Drawing.SystemColors.Control;
// this.tableLayoutPanel2.ColumnCount = 1;
// karaokeVideoPlayer1 this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
// this.tableLayoutPanel2.Controls.Add(this.materialListBox1, 0, 1);
this.karaokeVideoPlayer1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel2.Controls.Add(this.materialSingleLineTextField1, 0, 0);
this.karaokeVideoPlayer1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.karaokeVideoPlayer1.Name = "karaokeVideoPlayer1"; this.tableLayoutPanel2.Location = new System.Drawing.Point(0, 0);
this.karaokeVideoPlayer1.Size = new System.Drawing.Size(472, 458); this.tableLayoutPanel2.Name = "tableLayoutPanel2";
this.karaokeVideoPlayer1.TabIndex = 0; this.tableLayoutPanel2.RowCount = 2;
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel2.Size = new System.Drawing.Size(237, 458);
this.tableLayoutPanel2.TabIndex = 7;
// //
// materialListBox1 // materialListBox1
// //
@ -175,21 +181,21 @@
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);
// //
// tableLayoutPanel2 // karaokeCDGPlayer
// //
this.tableLayoutPanel2.BackColor = System.Drawing.SystemColors.Control; this.karaokeCDGPlayer.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel2.ColumnCount = 1; this.karaokeCDGPlayer.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.karaokeCDGPlayer.Name = "karaokeCDGPlayer";
this.tableLayoutPanel2.Controls.Add(this.materialListBox1, 0, 1); this.karaokeCDGPlayer.Size = new System.Drawing.Size(472, 458);
this.tableLayoutPanel2.Controls.Add(this.materialSingleLineTextField1, 0, 0); this.karaokeCDGPlayer.TabIndex = 0;
this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill; this.karaokeCDGPlayer.isCDG = true;
this.tableLayoutPanel2.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel2.Name = "tableLayoutPanel2"; this.karaokeMP4Player.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel2.RowCount = 2; this.karaokeMP4Player.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.karaokeMP4Player.Name = "karaokeMP4Player";
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.karaokeMP4Player.Size = new System.Drawing.Size(472, 458);
this.tableLayoutPanel2.Size = new System.Drawing.Size(237, 458); this.karaokeMP4Player.TabIndex = 0;
this.tableLayoutPanel2.TabIndex = 7; this.karaokeMP4Player.isCDG = false;
// //
// MainForm // MainForm
// //
@ -218,7 +224,8 @@
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private System.Windows.Forms.FolderBrowserDialog browseDialog; private System.Windows.Forms.FolderBrowserDialog browseDialog;
private System.Windows.Forms.SplitContainer splitContainer1; private System.Windows.Forms.SplitContainer splitContainer1;
private KaraokeVideoPlayer karaokeVideoPlayer1; private KaraokeVideoPlayer karaokeCDGPlayer;
private KaraokeVideoPlayer karaokeMP4Player;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2;
private MaterialSkin.Controls.MaterialListBox materialListBox1; private MaterialSkin.Controls.MaterialListBox materialListBox1;
private MaterialSkin.Controls.MaterialSingleLineTextField materialSingleLineTextField1; private MaterialSkin.Controls.MaterialSingleLineTextField materialSingleLineTextField1;

View File

@ -25,16 +25,16 @@ namespace KaraokePlayer
private void materialRaisedButton1_Click(object sender, System.EventArgs e) private void materialRaisedButton1_Click(object sender, System.EventArgs e)
{ {
karaokeVideoPlayer1.Play(new Uri(@"D:\Karaoke\SF360 February 2016\SF360-01 - Charlie Puth - One Call Away\SF360-01 - Charlie Puth - One Call Away.mp3")); playSelectedFile();
} }
private void btnBrowse_Click(object sender, EventArgs e) private void btnBrowse_Click(object sender, EventArgs e)
{ {
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 = System.IO.Directory.GetFiles(browseDialog.SelectedPath, "*.cdg", searchOption: System.IO.SearchOption.AllDirectories); var filtered = files.Where(f => f.Length < 248).ToList();
_fileList = files.Select(file => new FileInfo(file)).ToList(); _fileList = filtered.Select(file => new FileInfo(file)).ToList();
materialListBox1.DataSource = _fileList; materialListBox1.DataSource = _fileList;
materialListBox1.DisplayMember = "Name"; materialListBox1.DisplayMember = "Name";
@ -46,7 +46,7 @@ namespace KaraokePlayer
int index = this.materialListBox1.IndexFromPoint(e.Location); int index = this.materialListBox1.IndexFromPoint(e.Location);
if (index != System.Windows.Forms.ListBox.NoMatches) if (index != System.Windows.Forms.ListBox.NoMatches)
{ {
karaokeVideoPlayer1.Play(new Uri(Path.ChangeExtension(((FileInfo)materialListBox1.Items[index]).FullName,".mp3"))); playSelectedFile();
} }
} }
@ -55,5 +55,33 @@ namespace KaraokePlayer
materialListBox1.DataSource = _fileList.Where( materialListBox1.DataSource = _fileList.Where(
file => Regex.IsMatch(file.Name, materialSingleLineTextField1.Text, RegexOptions.IgnoreCase)).ToList(); file => Regex.IsMatch(file.Name, materialSingleLineTextField1.Text, RegexOptions.IgnoreCase)).ToList();
} }
public static string[] GetFiles(string path, string searchPattern, SearchOption searchOption)
{
string[] searchPatterns = searchPattern.Split('|');
List<string> files = new List<string>();
foreach (string sp in searchPatterns)
files.AddRange(System.IO.Directory.GetFiles(path, sp, searchOption));
files.Sort();
return files.ToArray();
}
public void playSelectedFile()
{
FileInfo file = (FileInfo)materialListBox1.SelectedItem;
if (file.Extension.ToLower() == ".cdg")
{
karaokeCDGPlayer.Play(new Uri(Path.ChangeExtension(file.FullName, ".mp3")));
karaokeCDGPlayer.Visible = true;
karaokeMP4Player.Visible = false;
}
else {
karaokeMP4Player.Play(new Uri(file.FullName));
karaokeMP4Player.Visible = true;
karaokeCDGPlayer.Visible = false;
}
}
} }
} }