159 lines
4.9 KiB
C#
159 lines
4.9 KiB
C#
using FireSharp;
|
|
using FireSharp.Config;
|
|
using FireSharp.Interfaces;
|
|
using KaraokePlayer.Classes;
|
|
using KaraokePlayer.Enums;
|
|
using KaraokePlayer.Interfaces;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using TagLib;
|
|
|
|
namespace TestSelector
|
|
{
|
|
|
|
public partial class Form1 : Form
|
|
{
|
|
FirebaseController controller;
|
|
|
|
public Form1()
|
|
{
|
|
|
|
InitializeComponent();
|
|
controller = new FirebaseController(
|
|
stateChanged: (args) =>
|
|
{
|
|
if (args.State == KaraokePlayer.Enums.PlayerState.Play)
|
|
{
|
|
this.Invoke(new Action(() => { buttonUpdateForPause(); }));
|
|
}
|
|
else if (args.State == KaraokePlayer.Enums.PlayerState.Pause)
|
|
{
|
|
this.Invoke(new Action(() => { buttonUpdateForPlay(); }));
|
|
}
|
|
},
|
|
songChanged: (args) =>
|
|
{
|
|
this.Invoke(new Action(() => { buttonUpdateForPlay(); }));
|
|
},
|
|
playQueueChanged:() => {
|
|
this.Invoke(new Action(() => { updatePlayQueue(); }));
|
|
}
|
|
);
|
|
|
|
}
|
|
private List<FileInfo> _fileList;
|
|
private List<ISong> _playQueue;
|
|
private void updatePlayQueue()
|
|
{
|
|
_playQueue = controller.PlayQueue;
|
|
listBox2.DataSource = null;
|
|
listBox2.DataSource = _playQueue;
|
|
listBox2.DisplayMember = "Description";
|
|
}
|
|
|
|
private void buttonUpdateForPlay()
|
|
{
|
|
button3.Text = "Play";
|
|
}
|
|
|
|
private void buttonUpdateForPause()
|
|
{
|
|
button3.Text = "Pause";
|
|
}
|
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
if (browseDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
var files = GetFiles(browseDialog.SelectedPath, "*.cdg|*.mp4", searchOption: System.IO.SearchOption.AllDirectories);
|
|
var filtered = files.Where(f => f.Length < 248).ToList();
|
|
_fileList = filtered.Select(file => new FileInfo(file)).ToList();
|
|
listBox1.DataSource = _fileList;
|
|
listBox1.DisplayMember = "Name";
|
|
|
|
}
|
|
}
|
|
private 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();
|
|
}
|
|
|
|
private void textBox1_TextChanged(object sender, EventArgs e)
|
|
{
|
|
listBox1.DataSource = _fileList.Where(file => Regex.IsMatch(file.Name, textBox1.Text, RegexOptions.IgnoreCase)).ToList();
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
FileInfo file = (FileInfo)listBox1.SelectedItem;
|
|
TagLib.File tag = null;
|
|
FirebaseSong song = new FirebaseSong();
|
|
if (file.Extension.ToLower() == ".cdg")
|
|
{
|
|
tag = TagLib.File.Create(Path.ChangeExtension(file.FullName, ".mp3"));
|
|
song.FileType = FileType.CDG;
|
|
}
|
|
else if (file.Extension.ToLower() == ".mp4")
|
|
{
|
|
tag = TagLib.File.Create(file.FullName);
|
|
song.FileType = FileType.MP4;
|
|
}
|
|
song.Order = 1;
|
|
song.Id = new Random().Next(0, 50000);
|
|
song.Title = tag.Tag.Title;
|
|
song.Artist = tag.Tag.Performers[0];
|
|
song.Path = file.FullName;
|
|
controller.AddSongToQueue(song);
|
|
}
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
if (button3.Text == "Play")
|
|
{
|
|
controller.Play();
|
|
} else
|
|
{
|
|
controller.Pause();
|
|
}
|
|
}
|
|
|
|
private void button4_Click(object sender, EventArgs e)
|
|
{
|
|
controller.Stop();
|
|
}
|
|
|
|
private void button5_Click(object sender, EventArgs e)
|
|
{
|
|
controller.RemoveSong(controller.CurrentSong);
|
|
controller.GetNextSong();
|
|
}
|
|
|
|
private void button6_Click(object sender, EventArgs e)
|
|
{
|
|
ISong song = (ISong)listBox2.SelectedItem;
|
|
controller.PlaySong(song);
|
|
}
|
|
|
|
private void button7_Click(object sender, EventArgs e)
|
|
{
|
|
ISong song = (ISong)listBox2.SelectedItem;
|
|
controller.RemoveSong(song);
|
|
}
|
|
}
|
|
}
|