fixed a few things

This commit is contained in:
Don Archer 2016-08-19 18:46:57 -07:00
parent 0097334902
commit 89254a245e
10 changed files with 111 additions and 40 deletions

View File

@ -21,7 +21,12 @@ namespace KaraokePlayer.Classes
private IFirebaseClient _client;
private ControllerStateChangedEventHandler _stateChanged;
private ControllerSongChangedEventHandler _songChanged;
public Settings Settings { get; set; }
private string SettingsPath
{
get { return string.Format("controllers/{0}/player/settings", this.Id); }
}
private string QueuePath
{
get { return string.Format("controllers/{0}/player/queue", this.Id); }
@ -38,20 +43,6 @@ namespace KaraokePlayer.Classes
public string Id { 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)
{
Id = clientId;
@ -59,6 +50,7 @@ namespace KaraokePlayer.Classes
_songChanged = songChanged;
_client = new FirebaseClient(config);
SetupListener();
Settings = _client.Get(SettingsPath).ResultAs<Settings>();
}
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()
{
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)
{
if (newstate == _state) return;

View File

@ -48,6 +48,7 @@
<Compile Include="PlayerState.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="QueueItem.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Singer.cs" />
<Compile Include="Song.cs" />
</ItemGroup>

15
Herse.Models/Settings.cs Normal file
View 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; }
}
}

View File

@ -8,7 +8,7 @@
<appSettings>
<add key="Firebase.Secret" value="9BQHUEJhScgK2FP10hvlToxTlGQpXT94Cvx01piO" />
<add key="Firebase.Path" value="https://herse.firebaseio.com/" />
<add key="KaraokePlayer.ControllerId" value="archer" />
<add key="KaraokePlayer.ControllerId" value="arch" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />

View File

@ -37,29 +37,33 @@
this.karaokeCDGPlayer.Dock = System.Windows.Forms.DockStyle.Fill;
this.karaokeCDGPlayer.isCDG = true;
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.Size = new System.Drawing.Size(506, 296);
this.karaokeCDGPlayer.Size = new System.Drawing.Size(796, 484);
this.karaokeCDGPlayer.TabIndex = 0;
//
// karaokeMP4Player
//
this.karaokeMP4Player.AutoSize = true;
this.karaokeMP4Player.Dock = System.Windows.Forms.DockStyle.Fill;
this.karaokeMP4Player.isCDG = false;
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.Size = new System.Drawing.Size(506, 296);
this.karaokeMP4Player.Size = new System.Drawing.Size(796, 484);
this.karaokeMP4Player.TabIndex = 0;
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
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.karaokeCDGPlayer);
this.Name = "MainForm";
this.Text = "Karaoke Player";
this.ResumeLayout(false);
this.PerformLayout();
}

View File

@ -21,11 +21,6 @@ namespace KaraokePlayer
private FirebaseController controller;
private PlayerWrapper player;
public void SongEnded()
{
controller.EndSong();
}
public MainForm()
{
InitializeComponent();
@ -35,16 +30,20 @@ namespace KaraokePlayer
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
this.ShowInTaskbar = true;
string controllerId = ConfigurationManager.AppSettings["KaraokePlayer.ControllerId"];
//labelParty.Text = string.Format("https://herse.firebaseapp.com/ party: {0}", controllerId);
controller = new FirebaseController(
clientId: ConfigurationManager.AppSettings["KaraokePlayer.ControllerId"],
clientId: controllerId,
stateChanged: (args) =>
{
switch (args.State)
{
case PlayerState.Playing:
this.Invoke(new Action(() => { player.play(); }));
this.Invoke(new Action(() => {
songInfoForm.Hide();
player.play();
}));
break;
case PlayerState.Paused:
this.Invoke(new Action(() => { player.pause(); }));
@ -61,16 +60,25 @@ namespace KaraokePlayer
this.Invoke(new Action(() => { previewSong(); }));
}
);
controller.SetState(PlayerState.Stopped);
}
public void SongEnded()
{
controller.EndSong();
}
private async void previewSong()
{
songInfoForm.Update(player.Song);
songInfoForm.Show();
await Task.Delay(TimeSpan.FromSeconds(5));
player.play();
controller.SetState(PlayerState.Playing);
songInfoForm.Hide();
if(controller.Settings == null || controller.Settings.AutoAdvance)
{
await Task.Delay(TimeSpan.FromSeconds(10));
player.play();
controller.SetState(PlayerState.Playing);
songInfoForm.Hide();
}
}
}
}

View File

@ -85,7 +85,14 @@ namespace KaraokePlayer
{
string playPath = null;
string extractPath = Path.Combine(Directory.GetCurrentDirectory(), "temp");
DeleteDirectory(extractPath);
try
{
DeleteDirectory(extractPath);
}
catch(Exception)
{
// do nothing
}
Directory.CreateDirectory(extractPath);
using (ZipArchive archive = ZipFile.OpenRead(Song.Path))
{

View File

@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Firebase.Secret" value="9BQHUEJhScgK2FP10hvlToxTlGQpXT94Cvx01piO" />
<add key="Firebase.Path" value="https://herse.firebaseio.com/" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>

View File

@ -9,6 +9,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Compression;
using System.Configuration;
namespace SongCrawler
{
@ -16,22 +17,32 @@ namespace SongCrawler
{
static void Main(string[] args)
{
if(args.Length != 2)
{
Console.WriteLine("usage: songcrawler partyid songspath");
return;
}
string controller = args[0];
string songpath = args[1];
IFirebaseConfig config = new FirebaseConfig
{
AuthSecret = "9BQHUEJhScgK2FP10hvlToxTlGQpXT94Cvx01piO",
BasePath = "https://herse.firebaseio.com/"
AuthSecret = ConfigurationManager.AppSettings["Firebase.Secret"],
BasePath = ConfigurationManager.AppSettings["Firebase.Path"]
};
FireSharp.FirebaseClient client = new FireSharp.FirebaseClient(config);
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>();
files.AddRange(FindFiles("mp3", songpath));
files.AddRange(FindFiles("zip", songpath));
files.AddRange(FindFiles("mp4", songpath));
List<Song> songs = new List<Song>();
Song song = null;
int i = 0;
foreach (string filepath in files)
@ -41,14 +52,14 @@ namespace SongCrawler
{
song = MakeSong(filepath);
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)
{
Console.WriteLine(ex.Message);
}
}
SetResponse response = client.Set(firepath, songs);
client.Set(firepath, songs);
}
private static Song MakeSong(string filepath)
@ -113,9 +124,9 @@ namespace SongCrawler
try
{
tagFile = TagLib.File.Create(path);
song.Title = tagFile.Tag.Title;
song.Artist = tagFile.Tag.FirstPerformer;
song.Genre = tagFile.Tag.FirstGenre;
song.Title = tagFile.Tag.Title.Trim();
song.Artist = tagFile.Tag.FirstPerformer.Trim();
song.Genre = tagFile.Tag.FirstGenre.Trim();
song.Year = (int)tagFile.Tag.Year;
}
catch

View File

@ -54,6 +54,7 @@
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />