moved player node outside of songs for speed
This commit is contained in:
parent
b6588ff28d
commit
0097334902
@ -17,18 +17,22 @@ namespace KaraokePlayer.Classes
|
|||||||
AuthSecret = ConfigurationManager.AppSettings["Firebase.Secret"],
|
AuthSecret = ConfigurationManager.AppSettings["Firebase.Secret"],
|
||||||
BasePath = ConfigurationManager.AppSettings["Firebase.Path"]
|
BasePath = ConfigurationManager.AppSettings["Firebase.Path"]
|
||||||
};
|
};
|
||||||
private PlayerState _state = PlayerState.playing;
|
private PlayerState _state = PlayerState.Playing;
|
||||||
private IFirebaseClient _client;
|
private IFirebaseClient _client;
|
||||||
private ControllerStateChangedEventHandler _stateChanged;
|
private ControllerStateChangedEventHandler _stateChanged;
|
||||||
private ControllerSongChangedEventHandler _songChanged;
|
private ControllerSongChangedEventHandler _songChanged;
|
||||||
|
|
||||||
|
private string QueuePath
|
||||||
|
{
|
||||||
|
get { return string.Format("controllers/{0}/player/queue", this.Id); }
|
||||||
|
}
|
||||||
private string StatePath
|
private string StatePath
|
||||||
{
|
{
|
||||||
get { return string.Format("controllers/{0}/state/", this.Id); }
|
get { return string.Format("controllers/{0}/player/state/", this.Id); }
|
||||||
}
|
}
|
||||||
private string CurrentSongPath
|
private string CurrentSongPath
|
||||||
{
|
{
|
||||||
get { return string.Format("controllers/{0}/queue/0/", this.Id); }
|
get { return string.Format("controllers/{0}/player/queue/0/", this.Id); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
@ -36,17 +40,16 @@ namespace KaraokePlayer.Classes
|
|||||||
|
|
||||||
public void EndSong()
|
public void EndSong()
|
||||||
{
|
{
|
||||||
//_client.DeleteAsync(CurrentSongPath.TrimEnd('/'));
|
var response = _client.Get(QueuePath);
|
||||||
var response = _client.Get(string.Format("controllers/{0}/queue", this.Id));
|
|
||||||
List<QueueItem> queue = response.ResultAs<List<QueueItem>>();
|
List<QueueItem> queue = response.ResultAs<List<QueueItem>>();
|
||||||
queue.RemoveAt(0);
|
queue.RemoveAt(0);
|
||||||
_client.Set(string.Format("controllers/{0}/queue", this.Id), queue);
|
_client.Set(QueuePath, queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetState(PlayerState state)
|
public void SetState(PlayerState state)
|
||||||
{
|
{
|
||||||
_state = state;
|
_state = state;
|
||||||
_client.SetAsync(StatePath, "playing");
|
_client.SetAsync(StatePath, "Playing");
|
||||||
}
|
}
|
||||||
|
|
||||||
public FirebaseController(string clientId, ControllerStateChangedEventHandler stateChanged, ControllerSongChangedEventHandler songChanged)
|
public FirebaseController(string clientId, ControllerStateChangedEventHandler stateChanged, ControllerSongChangedEventHandler songChanged)
|
||||||
@ -80,7 +83,7 @@ namespace KaraokePlayer.Classes
|
|||||||
changed: (s, args, obj) =>
|
changed: (s, args, obj) =>
|
||||||
{
|
{
|
||||||
Console.WriteLine("state changed " + args.Data);
|
Console.WriteLine("state changed " + args.Data);
|
||||||
PlayerState newstate = (PlayerState)Enum.Parse(typeof(PlayerState), args.Data);
|
PlayerState newstate = (PlayerState)Enum.Parse(typeof(PlayerState), args.Data, true);
|
||||||
StateDidChange(newstate);
|
StateDidChange(newstate);
|
||||||
},
|
},
|
||||||
removed: null
|
removed: null
|
||||||
@ -89,7 +92,7 @@ namespace KaraokePlayer.Classes
|
|||||||
|
|
||||||
private void CurrentSongDidChange()
|
private void CurrentSongDidChange()
|
||||||
{
|
{
|
||||||
var response = _client.Get(CurrentSongPath);
|
var response = _client.Get(CurrentSongPath);
|
||||||
var item = response.ResultAs<QueueItem>();
|
var item = response.ResultAs<QueueItem>();
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
if (CurrentSong == null || CurrentSong.Path != item.Song.Path)
|
if (CurrentSong == null || CurrentSong.Path != item.Song.Path)
|
||||||
|
|||||||
@ -8,8 +8,8 @@ namespace Herse.Models
|
|||||||
{
|
{
|
||||||
public enum PlayerState
|
public enum PlayerState
|
||||||
{
|
{
|
||||||
playing,
|
Playing,
|
||||||
stopped,
|
Stopped,
|
||||||
paused
|
Paused
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
<appSettings>
|
<appSettings>
|
||||||
<add key="Firebase.Secret" value="9BQHUEJhScgK2FP10hvlToxTlGQpXT94Cvx01piO" />
|
<add key="Firebase.Secret" value="9BQHUEJhScgK2FP10hvlToxTlGQpXT94Cvx01piO" />
|
||||||
<add key="Firebase.Path" value="https://herse.firebaseio.com/" />
|
<add key="Firebase.Path" value="https://herse.firebaseio.com/" />
|
||||||
<add key="KaraokePlayer.ControllerId" value="archer1" />
|
<add key="KaraokePlayer.ControllerId" value="archer" />
|
||||||
</appSettings>
|
</appSettings>
|
||||||
<startup>
|
<startup>
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||||
|
|||||||
@ -33,7 +33,7 @@ namespace KaraokePlayer
|
|||||||
player.OnSongEnded += SongEnded;
|
player.OnSongEnded += SongEnded;
|
||||||
|
|
||||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
||||||
//this.WindowState = FormWindowState.Maximized;
|
this.WindowState = FormWindowState.Maximized;
|
||||||
this.ShowInTaskbar = true;
|
this.ShowInTaskbar = true;
|
||||||
|
|
||||||
|
|
||||||
@ -43,13 +43,13 @@ namespace KaraokePlayer
|
|||||||
{
|
{
|
||||||
switch (args.State)
|
switch (args.State)
|
||||||
{
|
{
|
||||||
case PlayerState.playing:
|
case PlayerState.Playing:
|
||||||
this.Invoke(new Action(() => { player.play(); }));
|
this.Invoke(new Action(() => { player.play(); }));
|
||||||
break;
|
break;
|
||||||
case PlayerState.paused:
|
case PlayerState.Paused:
|
||||||
this.Invoke(new Action(() => { player.pause(); }));
|
this.Invoke(new Action(() => { player.pause(); }));
|
||||||
break;
|
break;
|
||||||
case PlayerState.stopped:
|
case PlayerState.Stopped:
|
||||||
this.Invoke(new Action(() => { player.stop(); }));
|
this.Invoke(new Action(() => { player.stop(); }));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ namespace KaraokePlayer
|
|||||||
songInfoForm.Show();
|
songInfoForm.Show();
|
||||||
await Task.Delay(TimeSpan.FromSeconds(5));
|
await Task.Delay(TimeSpan.FromSeconds(5));
|
||||||
player.play();
|
player.play();
|
||||||
controller.SetState(PlayerState.playing);
|
controller.SetState(PlayerState.Playing);
|
||||||
songInfoForm.Hide();
|
songInfoForm.Hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,32 +27,58 @@ namespace SongCrawler
|
|||||||
string firepath = string.Format("controllers/{0}/songs", controller);
|
string firepath = string.Format("controllers/{0}/songs", controller);
|
||||||
|
|
||||||
List<string> files = new List<string>();
|
List<string> files = new List<string>();
|
||||||
files.AddRange(Directory.GetFiles(songpath, "*.mp3", SearchOption.AllDirectories));
|
files.AddRange(FindFiles("mp3", songpath));
|
||||||
files.AddRange(Directory.GetFiles(songpath, "*.zip", SearchOption.AllDirectories));
|
files.AddRange(FindFiles("zip", songpath));
|
||||||
|
files.AddRange(FindFiles("mp4", songpath));
|
||||||
|
|
||||||
List<Song> songs = new List<Song>();
|
List<Song> songs = new List<Song>();
|
||||||
string id3path = null;
|
Song song = null;
|
||||||
Song song;
|
int i = 0;
|
||||||
foreach (string filepath in files)
|
foreach (string filepath in files)
|
||||||
{
|
{
|
||||||
Console.WriteLine(filepath);
|
i++;
|
||||||
var ext = Path.GetExtension(filepath).ToLower();
|
try
|
||||||
switch (ext)
|
|
||||||
{
|
{
|
||||||
case ".mp3":
|
song = MakeSong(filepath);
|
||||||
id3path = filepath;
|
Console.WriteLine(string.Format("{0:000000}/{1} - {2}", i, files.Count, song.Title));
|
||||||
break;
|
songs.Add(song);
|
||||||
case ".zip":
|
}
|
||||||
id3path = UnzipMp3(filepath);
|
catch(Exception ex)
|
||||||
break;
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
}
|
}
|
||||||
song = ReadId3(id3path);
|
|
||||||
CheckTitle(song);
|
|
||||||
song.Path = filepath;
|
|
||||||
songs.Add(song);
|
|
||||||
}
|
}
|
||||||
SetResponse response = client.Set(firepath, songs);
|
SetResponse response = client.Set(firepath, songs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Song MakeSong(string filepath)
|
||||||
|
{
|
||||||
|
|
||||||
|
Song song = null;
|
||||||
|
var ext = Path.GetExtension(filepath).ToLower();
|
||||||
|
switch (ext)
|
||||||
|
{
|
||||||
|
case ".mp3":
|
||||||
|
case ".mp4":
|
||||||
|
song = ReadId3(filepath);
|
||||||
|
break;
|
||||||
|
case ".zip":
|
||||||
|
song = ReadId3FromZip(filepath);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
CheckTitle(song);
|
||||||
|
song.Path = filepath;
|
||||||
|
return song;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string[] FindFiles(string ext, string path)
|
||||||
|
{
|
||||||
|
Console.Write(string.Format("\rscanning {0} for {1} - ", path, ext));
|
||||||
|
string[] files = Directory.GetFiles(path, "*." + ext, SearchOption.AllDirectories);
|
||||||
|
Console.WriteLine(string.Format("{0} found", files.Length));
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
private static void CheckTitle(Song song)
|
private static void CheckTitle(Song song)
|
||||||
{
|
{
|
||||||
if(string.IsNullOrEmpty(song.Title))
|
if(string.IsNullOrEmpty(song.Title))
|
||||||
@ -71,31 +97,33 @@ namespace SongCrawler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string UnzipMp3(string filepath)
|
private static Song ReadId3FromZip(string zippath)
|
||||||
{
|
{
|
||||||
string file = Path.GetFileNameWithoutExtension(filepath);
|
ZipFile.ExtractToDirectory(zippath, "c:\\temp");
|
||||||
try
|
string filepath = Directory.GetFiles("c:\\temp", "*.mp3")[0];
|
||||||
{
|
Song song = ReadId3(filepath);
|
||||||
ZipFile.ExtractToDirectory(filepath, "c:\\temp");
|
foreach (string file in Directory.GetFiles("c:\\temp")) File.Delete(file);
|
||||||
}
|
return song;
|
||||||
catch
|
|
||||||
{
|
|
||||||
// do nothing fancy
|
|
||||||
}
|
|
||||||
return "c:\\temp\\" + file + ".mp3";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Song ReadId3(string path)
|
static Song ReadId3(string path)
|
||||||
{
|
{
|
||||||
TagLib.File tagFile = TagLib.File.Create(path);
|
Song song = new Song();
|
||||||
return new Song()
|
TagLib.File tagFile;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Title = tagFile.Tag.Title,
|
tagFile = TagLib.File.Create(path);
|
||||||
Artist = tagFile.Tag.FirstPerformer,
|
song.Title = tagFile.Tag.Title;
|
||||||
Path = path,
|
song.Artist = tagFile.Tag.FirstPerformer;
|
||||||
Genre = tagFile.Tag.FirstGenre,
|
song.Genre = tagFile.Tag.FirstGenre;
|
||||||
Year = (int)tagFile.Tag.Year
|
song.Year = (int)tagFile.Tag.Year;
|
||||||
};
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// do nothing;
|
||||||
|
}
|
||||||
|
song.Path = path;
|
||||||
|
return song;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user