private void StopPlayingClick(object sender, RoutedEventArgs e) { if (SocketClientOut.waveOut.PlaybackState == NAudio.Wave.PlaybackState.Playing || SocketClientOut.waveOut.PlaybackState == NAudio.Wave.PlaybackState.Paused) { SocketClientOut.buffering = false; SocketClientOut.stopSong(); stopPlay.Content = "Play"; } else if (SocketClientOut.waveOut.PlaybackState == NAudio.Wave.PlaybackState.Stopped) { SocketClientOut.buffering = true; SocketClientOut.sendActionRequest(Encoding.ASCII.GetBytes("playMusic")); SocketClientOut.sendSongName(Encoding.ASCII.GetBytes(songName)); //SocketClientOut.sendSongName(Encoding.ASCII.GetBytes("haha")); var msg = Encoding.ASCII.GetString(SocketClientOut.receiveAccess()); if (msg == "granted") { ThreadStart receiveStart = new ThreadStart(SocketClientOut.receivingSong); Thread receiveThread = new Thread(receiveStart); receiveThread.Start(); //SocketClientOut.playSong(); } else { MessageBox.Show(msg); } stopPlay.Content = "Stop"; } }
private void Login_Click(object sender, RoutedEventArgs e) { if (user.Text == "" || pass.Password == "") { MessageBox.Show("id or password can't be empty"); } else { //SocketClientOut.accountEstablish(); SocketClientOut.connectionEstablish(); SocketClientOut.privatePort(); SocketClientOut.sendActionRequest(Encoding.ASCII.GetBytes("login")); SocketClientOut.sendIdAndPassword(Encoding.ASCII.GetBytes(user.Text), Encoding.ASCII.GetBytes(pass.Password)); var access = SocketClientOut.receiveAccess(); if (Encoding.ASCII.GetString(access) == "granted") { var st = Encoding.ASCII.GetString(SocketClientOut.receiveAccess()); User x = JsonConvert.DeserializeObject <User>(st); st = Encoding.ASCII.GetString(SocketClientOut.receiveAccess()); allSongs = JsonConvert.DeserializeObject <Playlist>(st); AfterLogin b = new AfterLogin(x); Reset(); this.Hide(); b.Show(); } else if (Encoding.ASCII.GetString(access) == "denied") { InvalidLogin.Visibility = Visibility.Visible; } } }
private void Login_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { if (user.Text == "" || pass.Password == "") { MessageBox.Show("id or password can't be empty"); } else { //SocketClientOut.accountEstablish(); SocketClientOut.connectionEstablish(); SocketClientOut.privatePort(); SocketClientOut.sendActionRequest(Encoding.ASCII.GetBytes("login")); SocketClientOut.sendIdAndPassword(Encoding.ASCII.GetBytes(user.Text), Encoding.ASCII.GetBytes(pass.Password)); var access = SocketClientOut.receiveAccess(); if (Encoding.ASCII.GetString(access) == "granted") { var st = Encoding.ASCII.GetString(SocketClientOut.receiveAccess()); User x = JsonConvert.DeserializeObject <User>(st); st = Encoding.ASCII.GetString(SocketClientOut.receiveAccess()); allSongs = JsonConvert.DeserializeObject <Playlist>(st); AfterLogin b = new AfterLogin(x); Reset(); this.Hide(); b.Show(); } else if (Encoding.ASCII.GetString(access) == "denied") { InvalidLogin.Visibility = Visibility.Visible; } } /* * var msg = "Incorrect Username or Password!"; * int counter = 0; * foreach (var x in everyUser.Users) * { * * if (user.Text == x.mUsername && pass.Password == x.mPassword) * { * AfterLogin b = new AfterLogin(x); * counter++; * Reset(); * this.Hide(); * b.Show(); * break; * } * * } * * if (counter == 0) * { * InvalidLogin.Visibility = Visibility.Visible; * //MessageBox.Show(msg); * } */ } }
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count != 0) { songName = ((Song)e.AddedItems[0]).ToString(); SocketClientOut.sendActionRequest(Encoding.ASCII.GetBytes("playMusic")); SocketClientOut.sendSongName(Encoding.ASCII.GetBytes(songName)); //SocketClientOut.sendSongName(Encoding.ASCII.GetBytes("haha")); var msg = Encoding.ASCII.GetString(SocketClientOut.receiveAccess()); if (msg == "granted") { ThreadStart receiveStart = new ThreadStart(SocketClientOut.receivingSong); Thread receiveThread = new Thread(receiveStart); SocketClientOut.buffering = true; receiveThread.Start(); //SocketClientOut.playSong(); } else { MessageBox.Show(msg); } /* * currPlaylistName = ((System.Windows.Controls.ListBox)e.OriginalSource).Tag.ToString(); * Playlist currentPL = objectUser.mPlaylists.Where(x => currPlaylistName.Equals(x.mName)).DefaultIfEmpty(null).Single(); * if (currentPL != null) * { * var wmpPL = ax.playlistCollection.newPlaylist("Current Playlist - " + currPlaylistName); * var startMedia = ax.newMedia(mediaFolder + "\\" + ((Song)e.AddedItems[0]).Directory); * startMedia.name = ((Song)e.AddedItems[0]).ToString(); * wmpPL.appendItem(startMedia); * foreach (Song cur in currentPL.mSongs) * { * if (!cur.mTitle.Equals(((Song)e.AddedItems[0]).mTitle)) * { * var fileLocation = mediaFolder + "\\" + cur.Directory; * var mediaItem = ax.newMedia(fileLocation); * wmpPL.appendItem(mediaItem); * } * } * ax.currentPlaylist = wmpPL; * * } * * * * //ax.URL = mediaFolder + "\\" + ((Song)e.AddedItems[0]).Directory; * //currMediaName = ((Song)e.AddedItems[0]).Directory; */ } }