fixed a few things
This commit is contained in:
parent
0097334902
commit
89254a245e
@ -21,7 +21,12 @@ namespace KaraokePlayer.Classes
|
|||||||
private IFirebaseClient _client;
|
private IFirebaseClient _client;
|
||||||
private ControllerStateChangedEventHandler _stateChanged;
|
private ControllerStateChangedEventHandler _stateChanged;
|
||||||
private ControllerSongChangedEventHandler _songChanged;
|
private ControllerSongChangedEventHandler _songChanged;
|
||||||
|
public Settings Settings { get; set; }
|
||||||
|
|
||||||
|
private string SettingsPath
|
||||||
|
{
|
||||||
|
get { return string.Format("controllers/{0}/player/settings", this.Id); }
|
||||||
|
}
|
||||||
private string QueuePath
|
private string QueuePath
|
||||||
{
|
{
|
||||||
get { return string.Format("controllers/{0}/player/queue", this.Id); }
|
get { return string.Format("controllers/{0}/player/queue", this.Id); }
|
||||||
@ -38,20 +43,6 @@ namespace KaraokePlayer.Classes
|
|||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public Song CurrentSong { get; set; }
|
public Song CurrentSong { get; set; }
|
||||||
|
|
||||||
public void EndSong()
|
|
||||||
{
|
|
||||||
var response = _client.Get(QueuePath);
|
|
||||||
List<QueueItem> queue = response.ResultAs<List<QueueItem>>();
|
|
||||||
queue.RemoveAt(0);
|
|
||||||
_client.Set(QueuePath, queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetState(PlayerState state)
|
|
||||||
{
|
|
||||||
_state = state;
|
|
||||||
_client.SetAsync(StatePath, "Playing");
|
|
||||||
}
|
|
||||||
|
|
||||||
public FirebaseController(string clientId, ControllerStateChangedEventHandler stateChanged, ControllerSongChangedEventHandler songChanged)
|
public FirebaseController(string clientId, ControllerStateChangedEventHandler stateChanged, ControllerSongChangedEventHandler songChanged)
|
||||||
{
|
{
|
||||||
Id = clientId;
|
Id = clientId;
|
||||||
@ -59,6 +50,7 @@ namespace KaraokePlayer.Classes
|
|||||||
_songChanged = songChanged;
|
_songChanged = songChanged;
|
||||||
_client = new FirebaseClient(config);
|
_client = new FirebaseClient(config);
|
||||||
SetupListener();
|
SetupListener();
|
||||||
|
Settings = _client.Get(SettingsPath).ResultAs<Settings>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupListener()
|
private void SetupListener()
|
||||||
@ -90,6 +82,30 @@ namespace KaraokePlayer.Classes
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// called by the player to end the current song in firebase
|
||||||
|
/// </summary>
|
||||||
|
public void EndSong()
|
||||||
|
{
|
||||||
|
SetState(PlayerState.Stopped);
|
||||||
|
List<QueueItem> queue = _client.Get(QueuePath).ResultAs<List<QueueItem>>();
|
||||||
|
queue.RemoveAt(0);
|
||||||
|
_client.Set(QueuePath, queue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// called by the player to set the state in firebase
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="state"></param>
|
||||||
|
public void SetState(PlayerState state)
|
||||||
|
{
|
||||||
|
_state = state;
|
||||||
|
_client.SetAsync(StatePath, "Playing");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// called by firebase to change the current song
|
||||||
|
/// </summary>
|
||||||
private void CurrentSongDidChange()
|
private void CurrentSongDidChange()
|
||||||
{
|
{
|
||||||
var response = _client.Get(CurrentSongPath);
|
var response = _client.Get(CurrentSongPath);
|
||||||
@ -102,6 +118,10 @@ namespace KaraokePlayer.Classes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// called by firebase to change the current state
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="newstate"></param>
|
||||||
private void StateDidChange(PlayerState newstate)
|
private void StateDidChange(PlayerState newstate)
|
||||||
{
|
{
|
||||||
if (newstate == _state) return;
|
if (newstate == _state) return;
|
||||||
|
|||||||
@ -48,6 +48,7 @@
|
|||||||
<Compile Include="PlayerState.cs" />
|
<Compile Include="PlayerState.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="QueueItem.cs" />
|
<Compile Include="QueueItem.cs" />
|
||||||
|
<Compile Include="Settings.cs" />
|
||||||
<Compile Include="Singer.cs" />
|
<Compile Include="Singer.cs" />
|
||||||
<Compile Include="Song.cs" />
|
<Compile Include="Song.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
15
Herse.Models/Settings.cs
Normal file
15
Herse.Models/Settings.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Herse.Models
|
||||||
|
{
|
||||||
|
public class Settings
|
||||||
|
{
|
||||||
|
[JsonProperty("autoadvance")]
|
||||||
|
public bool AutoAdvance { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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="archer" />
|
<add key="KaraokePlayer.ControllerId" value="arch" />
|
||||||
</appSettings>
|
</appSettings>
|
||||||
<startup>
|
<startup>
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||||
|
|||||||
10
KaraokePlayer/MainForm.Designer.cs
generated
10
KaraokePlayer/MainForm.Designer.cs
generated
@ -37,29 +37,33 @@
|
|||||||
this.karaokeCDGPlayer.Dock = System.Windows.Forms.DockStyle.Fill;
|
this.karaokeCDGPlayer.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.karaokeCDGPlayer.isCDG = true;
|
this.karaokeCDGPlayer.isCDG = true;
|
||||||
this.karaokeCDGPlayer.Location = new System.Drawing.Point(0, 0);
|
this.karaokeCDGPlayer.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.karaokeCDGPlayer.Margin = new System.Windows.Forms.Padding(3, 53, 3, 3);
|
||||||
this.karaokeCDGPlayer.Name = "karaokeCDGPlayer";
|
this.karaokeCDGPlayer.Name = "karaokeCDGPlayer";
|
||||||
this.karaokeCDGPlayer.Size = new System.Drawing.Size(506, 296);
|
this.karaokeCDGPlayer.Size = new System.Drawing.Size(796, 484);
|
||||||
this.karaokeCDGPlayer.TabIndex = 0;
|
this.karaokeCDGPlayer.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// karaokeMP4Player
|
// karaokeMP4Player
|
||||||
//
|
//
|
||||||
|
this.karaokeMP4Player.AutoSize = true;
|
||||||
this.karaokeMP4Player.Dock = System.Windows.Forms.DockStyle.Fill;
|
this.karaokeMP4Player.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
this.karaokeMP4Player.isCDG = false;
|
this.karaokeMP4Player.isCDG = false;
|
||||||
this.karaokeMP4Player.Location = new System.Drawing.Point(0, 0);
|
this.karaokeMP4Player.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.karaokeMP4Player.Margin = new System.Windows.Forms.Padding(3, 53, 3, 3);
|
||||||
this.karaokeMP4Player.Name = "karaokeMP4Player";
|
this.karaokeMP4Player.Name = "karaokeMP4Player";
|
||||||
this.karaokeMP4Player.Size = new System.Drawing.Size(506, 296);
|
this.karaokeMP4Player.Size = new System.Drawing.Size(796, 484);
|
||||||
this.karaokeMP4Player.TabIndex = 0;
|
this.karaokeMP4Player.TabIndex = 0;
|
||||||
//
|
//
|
||||||
// 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(506, 296);
|
this.ClientSize = new System.Drawing.Size(796, 484);
|
||||||
this.Controls.Add(this.karaokeMP4Player);
|
this.Controls.Add(this.karaokeMP4Player);
|
||||||
this.Controls.Add(this.karaokeCDGPlayer);
|
this.Controls.Add(this.karaokeCDGPlayer);
|
||||||
this.Name = "MainForm";
|
this.Name = "MainForm";
|
||||||
this.Text = "Karaoke Player";
|
this.Text = "Karaoke Player";
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -21,11 +21,6 @@ namespace KaraokePlayer
|
|||||||
private FirebaseController controller;
|
private FirebaseController controller;
|
||||||
private PlayerWrapper player;
|
private PlayerWrapper player;
|
||||||
|
|
||||||
public void SongEnded()
|
|
||||||
{
|
|
||||||
controller.EndSong();
|
|
||||||
}
|
|
||||||
|
|
||||||
public MainForm()
|
public MainForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -35,16 +30,20 @@ namespace KaraokePlayer
|
|||||||
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;
|
||||||
|
string controllerId = ConfigurationManager.AppSettings["KaraokePlayer.ControllerId"];
|
||||||
|
//labelParty.Text = string.Format("https://herse.firebaseapp.com/ party: {0}", controllerId);
|
||||||
|
|
||||||
controller = new FirebaseController(
|
controller = new FirebaseController(
|
||||||
clientId: ConfigurationManager.AppSettings["KaraokePlayer.ControllerId"],
|
clientId: controllerId,
|
||||||
stateChanged: (args) =>
|
stateChanged: (args) =>
|
||||||
{
|
{
|
||||||
switch (args.State)
|
switch (args.State)
|
||||||
{
|
{
|
||||||
case PlayerState.Playing:
|
case PlayerState.Playing:
|
||||||
this.Invoke(new Action(() => { player.play(); }));
|
this.Invoke(new Action(() => {
|
||||||
|
songInfoForm.Hide();
|
||||||
|
player.play();
|
||||||
|
}));
|
||||||
break;
|
break;
|
||||||
case PlayerState.Paused:
|
case PlayerState.Paused:
|
||||||
this.Invoke(new Action(() => { player.pause(); }));
|
this.Invoke(new Action(() => { player.pause(); }));
|
||||||
@ -61,16 +60,25 @@ namespace KaraokePlayer
|
|||||||
this.Invoke(new Action(() => { previewSong(); }));
|
this.Invoke(new Action(() => { previewSong(); }));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
controller.SetState(PlayerState.Stopped);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SongEnded()
|
||||||
|
{
|
||||||
|
controller.EndSong();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void previewSong()
|
private async void previewSong()
|
||||||
{
|
{
|
||||||
songInfoForm.Update(player.Song);
|
songInfoForm.Update(player.Song);
|
||||||
songInfoForm.Show();
|
songInfoForm.Show();
|
||||||
await Task.Delay(TimeSpan.FromSeconds(5));
|
if(controller.Settings == null || controller.Settings.AutoAdvance)
|
||||||
|
{
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(10));
|
||||||
player.play();
|
player.play();
|
||||||
controller.SetState(PlayerState.Playing);
|
controller.SetState(PlayerState.Playing);
|
||||||
songInfoForm.Hide();
|
songInfoForm.Hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,7 +85,14 @@ namespace KaraokePlayer
|
|||||||
{
|
{
|
||||||
string playPath = null;
|
string playPath = null;
|
||||||
string extractPath = Path.Combine(Directory.GetCurrentDirectory(), "temp");
|
string extractPath = Path.Combine(Directory.GetCurrentDirectory(), "temp");
|
||||||
|
try
|
||||||
|
{
|
||||||
DeleteDirectory(extractPath);
|
DeleteDirectory(extractPath);
|
||||||
|
}
|
||||||
|
catch(Exception)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
Directory.CreateDirectory(extractPath);
|
Directory.CreateDirectory(extractPath);
|
||||||
using (ZipArchive archive = ZipFile.OpenRead(Song.Path))
|
using (ZipArchive archive = ZipFile.OpenRead(Song.Path))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
<appSettings>
|
||||||
|
<add key="Firebase.Secret" value="9BQHUEJhScgK2FP10hvlToxTlGQpXT94Cvx01piO" />
|
||||||
|
<add key="Firebase.Path" value="https://herse.firebaseio.com/" />
|
||||||
|
</appSettings>
|
||||||
<startup>
|
<startup>
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||||
</startup>
|
</startup>
|
||||||
|
|||||||
@ -9,6 +9,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
namespace SongCrawler
|
namespace SongCrawler
|
||||||
{
|
{
|
||||||
@ -16,22 +17,32 @@ namespace SongCrawler
|
|||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
if(args.Length != 2)
|
||||||
|
{
|
||||||
|
Console.WriteLine("usage: songcrawler partyid songspath");
|
||||||
|
return;
|
||||||
|
}
|
||||||
string controller = args[0];
|
string controller = args[0];
|
||||||
string songpath = args[1];
|
string songpath = args[1];
|
||||||
IFirebaseConfig config = new FirebaseConfig
|
IFirebaseConfig config = new FirebaseConfig
|
||||||
{
|
{
|
||||||
AuthSecret = "9BQHUEJhScgK2FP10hvlToxTlGQpXT94Cvx01piO",
|
AuthSecret = ConfigurationManager.AppSettings["Firebase.Secret"],
|
||||||
BasePath = "https://herse.firebaseio.com/"
|
BasePath = ConfigurationManager.AppSettings["Firebase.Path"]
|
||||||
};
|
};
|
||||||
FireSharp.FirebaseClient client = new FireSharp.FirebaseClient(config);
|
FireSharp.FirebaseClient client = new FireSharp.FirebaseClient(config);
|
||||||
string firepath = string.Format("controllers/{0}/songs", controller);
|
string firepath = string.Format("controllers/{0}/songs", controller);
|
||||||
|
Console.WriteLine("Loading current library");
|
||||||
|
List<Song> songs = client.Get(firepath).ResultAs<List<Song>>();
|
||||||
|
if (songs != null)
|
||||||
|
Console.WriteLine(string.Format("{0} songs loaded", songs.Count));
|
||||||
|
else
|
||||||
|
songs = new List<Song>();
|
||||||
|
|
||||||
List<string> files = new List<string>();
|
List<string> files = new List<string>();
|
||||||
files.AddRange(FindFiles("mp3", songpath));
|
files.AddRange(FindFiles("mp3", songpath));
|
||||||
files.AddRange(FindFiles("zip", songpath));
|
files.AddRange(FindFiles("zip", songpath));
|
||||||
files.AddRange(FindFiles("mp4", songpath));
|
files.AddRange(FindFiles("mp4", songpath));
|
||||||
|
|
||||||
List<Song> songs = new List<Song>();
|
|
||||||
Song song = null;
|
Song song = null;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (string filepath in files)
|
foreach (string filepath in files)
|
||||||
@ -41,14 +52,14 @@ namespace SongCrawler
|
|||||||
{
|
{
|
||||||
song = MakeSong(filepath);
|
song = MakeSong(filepath);
|
||||||
Console.WriteLine(string.Format("{0:000000}/{1} - {2}", i, files.Count, song.Title));
|
Console.WriteLine(string.Format("{0:000000}/{1} - {2}", i, files.Count, song.Title));
|
||||||
songs.Add(song);
|
if(!songs.Any(s => s.Path == song.Path)) songs.Add(song);
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine(ex.Message);
|
Console.WriteLine(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetResponse response = client.Set(firepath, songs);
|
client.Set(firepath, songs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Song MakeSong(string filepath)
|
private static Song MakeSong(string filepath)
|
||||||
@ -113,9 +124,9 @@ namespace SongCrawler
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
tagFile = TagLib.File.Create(path);
|
tagFile = TagLib.File.Create(path);
|
||||||
song.Title = tagFile.Tag.Title;
|
song.Title = tagFile.Tag.Title.Trim();
|
||||||
song.Artist = tagFile.Tag.FirstPerformer;
|
song.Artist = tagFile.Tag.FirstPerformer.Trim();
|
||||||
song.Genre = tagFile.Tag.FirstGenre;
|
song.Genre = tagFile.Tag.FirstGenre.Trim();
|
||||||
song.Year = (int)tagFile.Tag.Year;
|
song.Year = (int)tagFile.Tag.Year;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|||||||
@ -54,6 +54,7 @@
|
|||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.configuration" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.IO.Compression" />
|
<Reference Include="System.IO.Compression" />
|
||||||
<Reference Include="System.IO.Compression.FileSystem" />
|
<Reference Include="System.IO.Compression.FileSystem" />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user