85 lines
2.9 KiB
C#
85 lines
2.9 KiB
C#
using System;
|
|
using MaterialSkin;
|
|
using MaterialSkin.Controls;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using System.IO.Compression;
|
|
using System.Windows.Forms;
|
|
using KaraokePlayer.Classes;
|
|
using System.Threading.Tasks;
|
|
using System.Configuration;
|
|
using Herse.Models;
|
|
|
|
namespace KaraokePlayer
|
|
{
|
|
public partial class MainForm : Form
|
|
{
|
|
private SongInfoForm songInfoForm = new SongInfoForm();
|
|
private delegate void Action();
|
|
private FirebaseController controller;
|
|
private PlayerWrapper player;
|
|
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
player = new PlayerWrapper(karaokeCDGPlayer, karaokeMP4Player);
|
|
player.OnSongEnded += SongEnded;
|
|
|
|
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: controllerId,
|
|
stateChanged: (args) =>
|
|
{
|
|
switch (args.State)
|
|
{
|
|
case PlayerState.Playing:
|
|
this.Invoke(new Action(() => {
|
|
songInfoForm.Hide();
|
|
player.play();
|
|
}));
|
|
break;
|
|
case PlayerState.Paused:
|
|
this.Invoke(new Action(() => { player.pause(); }));
|
|
break;
|
|
case PlayerState.Stopped:
|
|
this.Invoke(new Action(() => { player.stop(); }));
|
|
break;
|
|
}
|
|
},
|
|
songChanged: (args) =>
|
|
{
|
|
this.Invoke(new Action(() => { player.stop(); }));
|
|
player.QueueItem = args.QueueItem;
|
|
this.Invoke(new Action(() => { previewSong(); }));
|
|
}
|
|
);
|
|
controller.SetState(PlayerState.Stopped);
|
|
}
|
|
|
|
public void SongEnded()
|
|
{
|
|
controller.EndSong();
|
|
}
|
|
|
|
private async void previewSong()
|
|
{
|
|
songInfoForm.Update(player.QueueItem);
|
|
songInfoForm.Show();
|
|
if(controller.Settings == null || controller.Settings.AutoAdvance)
|
|
{
|
|
await Task.Delay(TimeSpan.FromSeconds(5));
|
|
player.play();
|
|
controller.SetState(PlayerState.Playing);
|
|
songInfoForm.Hide();
|
|
}
|
|
}
|
|
}
|
|
}
|