cleaned up firebase controller a little more

This commit is contained in:
Don Archer 2016-08-04 21:05:52 -07:00
parent 8b49afb0f3
commit caeca57cc9
2 changed files with 34 additions and 31 deletions

View File

@ -17,7 +17,7 @@ namespace KaraokePlayer.Classes
AuthSecret = ConfigurationManager.AppSettings["Firebase.Secret"], AuthSecret = ConfigurationManager.AppSettings["Firebase.Secret"],
BasePath = ConfigurationManager.AppSettings["Firebase.Path"] BasePath = ConfigurationManager.AppSettings["Firebase.Path"]
}; };
private string _state = "stop"; private string _state = "play";
private IFirebaseClient _client; private IFirebaseClient _client;
private ControllerStateChangedEventHandler _stateChanged; private ControllerStateChangedEventHandler _stateChanged;
private ControllerSongChangedEventHandler _songChanged; private ControllerSongChangedEventHandler _songChanged;
@ -69,13 +69,13 @@ namespace KaraokePlayer.Classes
public void PlaySong(Song song) { Update(string.Format("Controllers/{0}", this.Id), new { CurrentSong = song }); } public void PlaySong(Song song) { Update(string.Format("Controllers/{0}", this.Id), new { CurrentSong = song }); }
public void Next() { this.State = "Next"; } public void Next() { this.State = "next"; }
public void Play() { this.State = "Play"; } public void Play() { this.State = "play"; }
public void Stop() { this.State = "Stop"; } public void Stop() { this.State = "stop"; }
public void Pause() { this.State = "Pause"; } public void Pause() { this.State = "pause"; }
private void Delete(string path) { _client.DeleteAsync(path); } private void Delete(string path) { _client.DeleteAsync(path); }
@ -93,21 +93,28 @@ namespace KaraokePlayer.Classes
await _client.OnAsync(CurrentSongPath, await _client.OnAsync(CurrentSongPath,
added: (s, args, obj) => added: (s, args, obj) =>
{ {
if (args.Path == "/singer/name") Console.WriteLine("added " + args.Path + " " + args.Data);
{ CurrentSongDidChange();
Console.WriteLine("added " + args.Path + " " + args.Data);
CurrentSongDidChange();
}
}, },
removed: (s, args, obj) => removed: (s, args, obj) =>
{ {
//TODO: the current song was removed from the queue //TODO: the current song was removed from the queue
if (args.Path == "/singer")
{
Console.WriteLine("removed " + args.Path);
}
} }
); );
await _client.OnAsync(StatePath,
added: (s, args, obj) =>
{
Console.WriteLine("state added");
StateDidChange(args.Data);
},
changed: (s, args, obj) =>
{
Console.WriteLine("state changed");
StateDidChange(args.Data);
},
removed: null
);
/* /*
await _client.OnAsync(PlayQueuePath, await _client.OnAsync(PlayQueuePath,
added: (s, args, obj) => added: (s, args, obj) =>
@ -166,8 +173,7 @@ namespace KaraokePlayer.Classes
private void CurrentSongDidChange() private void CurrentSongDidChange()
{ {
var response = _client.Get(CurrentSongPath); var item = _client.Get(CurrentSongPath).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)
{ {
@ -179,20 +185,18 @@ namespace KaraokePlayer.Classes
private void StateDidChange(string state) private void StateDidChange(string state)
{ {
_state = state; _state = state;
PlayerState s = PlayerState.Play; switch(state)
if (state.ToLower() == "pause")
{ {
s = PlayerState.Pause; case "pause":
_stateChanged(new ControllerStateChangedEventArgs(PlayerState.Pause));
break;
case "stop":
_stateChanged(new ControllerStateChangedEventArgs(PlayerState.Stop));
break;
case "play":
_stateChanged(new ControllerStateChangedEventArgs(PlayerState.Play));
break;
} }
else if (state.ToLower() == "stop")
{
s = PlayerState.Stop;
}
else if (state == "next")
{
s = PlayerState.Next;
}
//_stateChanged(new ControllerStateChangedEventArgs(s));
} }
} }

View File

@ -30,7 +30,7 @@ namespace KaraokePlayer
karaokeMP4Player.songEndedHandler += new KaraokePlayer.KaraokeVideoPlayer.SongEndedEventHandler(this.karaokePlayerSongEnded); karaokeMP4Player.songEndedHandler += new KaraokePlayer.KaraokeVideoPlayer.SongEndedEventHandler(this.karaokePlayerSongEnded);
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;
karaokeCDGPlayer.Dock = DockStyle.Fill; karaokeCDGPlayer.Dock = DockStyle.Fill;
karaokeMP4Player.Dock = DockStyle.Fill; karaokeMP4Player.Dock = DockStyle.Fill;
@ -71,7 +71,6 @@ namespace KaraokePlayer
songInfoForm.Update(currentSong); songInfoForm.Update(currentSong);
songInfoForm.Show(); songInfoForm.Show();
await Task.Delay(TimeSpan.FromSeconds(5)); await Task.Delay(TimeSpan.FromSeconds(5));
//controller.Play();
play(); play();
songInfoForm.Hide(); songInfoForm.Hide();
} }