public static void PrecacheMusicData( ) { int NewIndex = CurrentSongIndex + 1; if (NewIndex > Songs.Count) { NewIndex = 0; } SongList NewSong = Music.FindSongByIndex(NewIndex); if (File.Exists(NewSong.SongLocation)) { FileStream FileStream = new FileStream(NewSong.SongLocation, FileMode.Open); using (MemoryStream CachedMusicMS = new MemoryStream( )) { FileStream.CopyTo(CurrentMusicMS); FileStream.Close( ); CachedMusicMS.Position = 0; MusicBase64Cache = Convert.ToBase64String(CachedMusicMS.ToArray( )); } Console.WriteLine("PrecacheMusicData : " + NewSong.SongAuthor + " - " + NewSong.SongName + " [" + CurrentSongIndex + "]"); } }
public static void InitializeCycle( ) { CurrentSongIndex = 0; SongList NewSong = Music.FindSongByIndex(CurrentSongIndex); Console.WriteLine("Initialize Cycle : " + NewSong.SongAuthor + " - " + NewSong.SongName + " [" + CurrentSongIndex + "]"); if (File.Exists(NewSong.SongLocation)) { FileStream FileStream = new FileStream(NewSong.SongLocation, FileMode.Open); CurrentMusicMS = new MemoryStream( ); FileStream.CopyTo(CurrentMusicMS); FileStream.Close( ); string Base64 = Convert.ToBase64String(CurrentMusicMS.ToArray( )); Music.MusicBase64Cache = Base64; CurrentSongTickLocation = 0; CurrentSongTickMaxLocation = NewSong.SongLength + 5; string data = Protocol.MakeProtocol <ClientProtocolMessage>(ClientProtocolMessage.MusicPlay, Music.MusicBase64Cache); string infoData = Protocol.MakeProtocol <ClientProtocolMessage>(ClientProtocolMessage.MusicInformation, MakeSongInformationForProtocolSend(GetCurrentSong( ))); for (int i = 0; i < Server.Clients.Count; i++) { Client Client = Server.Clients[i]; Client.SendData(data, () => { Console.WriteLine("음악 데이터 전송 ... [ " + Client.ClientData.Value.IP + " ][ " + Client.ClientData.Value.Nick + " ]"); Client.SendData(infoData, () => { Console.WriteLine("음악 정보 데이터 전송 ... [ " + Client.ClientData.Value.IP + " ][ " + Client.ClientData.Value.Nick + " ]"); }); }); } } else { // Song file Not found } SongTickTimer = new Timer( ); SongTickTimer.Interval = 1000; SongTickTimer.Elapsed += new ElapsedEventHandler(SongTickTimer_Elapsed); SongTickTimer.Start( ); }
public static void NextCycle( ) { if (CurrentSongIndex < Songs.Count) { CurrentSongIndex++; } else { CurrentSongIndex = 0; } SongList NewSong = Music.FindSongByIndex(CurrentSongIndex); Console.WriteLine("Next Cycle : " + NewSong.SongAuthor + " - " + NewSong.SongName + " [" + CurrentSongIndex + "]"); if (File.Exists(NewSong.SongLocation)) { FileStream FileStream = new FileStream(NewSong.SongLocation, FileMode.Open); CurrentMusicMS = new MemoryStream( ); FileStream.CopyTo(CurrentMusicMS); FileStream.Close( ); CurrentSongTickLocation = 0; CurrentSongTickMaxLocation = NewSong.SongLength + 5; string data = Protocol.MakeProtocol <ClientProtocolMessage>(ClientProtocolMessage.MusicPlay, Music.MusicBase64Cache); string infoData = Protocol.MakeProtocol <ClientProtocolMessage>(ClientProtocolMessage.MusicInformation, MakeSongInformationForProtocolSend(GetCurrentSong( ))); for (int i = 0; i < Server.Clients.Count; i++) { Client Client = Server.Clients[i]; Client.SendData(data, () => { Console.WriteLine("음악 데이터 전송 ... [ " + Client.ClientData.Value.IP + " ][ " + Client.ClientData.Value.Nick + " ]"); Client.SendData(infoData, () => { Console.WriteLine("음악 정보 데이터 전송 ... [ " + Client.ClientData.Value.IP + " ][ " + Client.ClientData.Value.Nick + " ]"); }); }); } } else { // Song Not found } }
public static string MakeSongInformationForProtocolSend(SongList Song) { return(string.Format("{0}#{1}#{2}", Song.SongName, Song.SongAuthor, CurrentSongTickLocation)); }