public ucVoicePanel(User user, FrmUser userForm) { InitializeComponent(); InitPictureBox(); this.user = user; this.userForm = userForm; voice = new VoiceControl(user); voice.Path = voice.GetNextPath(); timer = new Timer(); timer.Tick += Timer_Tick; timer.Interval = 1000; this.panelRecord.Controls.Add(pctRecord); }
public ucVoicePanel(Group group, FrmGroup groupForm) { InitializeComponent(); InitPictureBox(); this.group = group; this.groupForm = groupForm; voice = new VoiceControl(group); voice.Path = voice.GetNextPath(); timer = new Timer(); timer.Tick += Timer_Tick; timer.Interval = 1000; this.panelRecord.Controls.Add(pctRecord); }
private async void SendVoiceToServer() { try { if (voice.GetWave() == null) { return; } voice.DisposeAll(); byte[] data = File.ReadAllBytes(voice.Path); Guid id = Guid.NewGuid(); if (user != null) { byte[] tempBuff = Encoding.UTF8.GetBytes(string.Format("STARTSENDVOICE%{0}%{1}%{2}%{3}", user.Id, data.Length, id.ToString(), "Private")); SmallPackage smallPackage = new SmallPackage(0, 1024, "M", tempBuff, "0"); FrmMain.server.GetStream().WriteAsync(smallPackage.Packing(), 0, smallPackage.Packing().Length); FrmMain.client.SendFileToServer(data, "V", id.ToString()); userForm.AddVoiceMessage(FrmMain.me, voice.Path); } else { byte[] tempBuff = Encoding.UTF8.GetBytes(string.Format("STARTSENDVOICE%{0}%{1}%{2}%{3}", group.ID, data.Length, id.ToString(), "Public")); SmallPackage smallPackage = new SmallPackage(0, 1024, "M", tempBuff, "0"); FrmMain.server.GetStream().WriteAsync(smallPackage.Packing(), 0, smallPackage.Packing().Length); FrmMain.client.SendFileToServer(data, "V", id.ToString()); groupForm.AddVoiceMessage(FrmMain.me, voice.Path); } // Process when record sent voice.Path = voice.GetNextPath(); } catch (Exception ex) { MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }