public void SaveSample(SoundboardSample soundboardSample) { try { // Trimming if (soundboardSample.FileTimeUpperValue != soundboardSample.FileTimeMax || soundboardSample.FileTimeLowerValue != soundboardSample.FileTimeMin) { AudioAgent.TrimFile(soundboardSample.FilePath, soundboardSample.FileTimeLowerValue * 1000, soundboardSample.FileTimeUpperValue * 1000); soundboardSample.FileTimeMin = 0; soundboardSample.FileTimeMax = AudioAgent.GetFileAudioDuration(soundboardSample.FilePath).TotalSeconds; soundboardSample.FileTimeLowerValue = 0; soundboardSample.FileTimeUpperValue = soundboardSample.FileTimeMax; } // File name if (Path.GetFileNameWithoutExtension(soundboardSample.FilePath) != soundboardSample.Name) { string targetDirectory = Path.Combine(ApplicationConfiguration.Instance.SoundboardSampleDirectory, soundboardSample.GroupName == "Ungrouped" ? string.Empty : soundboardSample.GroupName); string newFilePath = soundboardSample.GetVirtualFilePath(); Directory.CreateDirectory(targetDirectory); File.Move(soundboardSample.FilePath, newFilePath); soundboardSample.FilePath = newFilePath; } soundboardSample.SaveMetadataProperties(); } catch (Exception ex) { ApplicationLogger.Log(ex.Message, ex.StackTrace); } }
public async Task DeleteSampleAsync(SoundboardSample soundboardSample) { try { // Recursively try to acquire file lock. This can sometimes take a few seconds to release after // an audio playback event has ended bool success = false; while (!success) { try { AudioAgent.StopAudioPlayback(SelectedOutputDevicesCollection.ToList()); File.Delete(soundboardSample.FilePath); SoundboardSampleCollection.Remove(soundboardSample); success = true; } catch { await Task.Delay(500); } } } catch (Exception ex) { ApplicationLogger.Log(ex.Message, ex.StackTrace); } }
public void PlayAudioSample(SoundboardSample soundboardSample, PlaybackScope playbackScope) { try { var outputDevices = SelectedOutputDevicesCollection.Where(x => x.PlaybackScope >= playbackScope).ToList(); if (outputDevices.Any()) { outputDevices[0].PlaybackStopped += OnAudioPlaybackStopped; soundboardSample.StartPlaybackTimer(); } outputDevices.ForEach(outputDevice => { AudioAgent.BeginAudioPlayback(soundboardSample.FilePath, outputDevice, (float)soundboardSample.Volume / (float)100, soundboardSample.FileTimeLowerValue, soundboardSample.FileTimeUpperValue); }); } catch (Exception ex) { ApplicationLogger.Log(ex.Message, ex.StackTrace); } }
public void OnFileWritten(object sender, EventArgs e) { try { string filePath = sender as string; double totalSeconds = AudioAgent.GetFileAudioDuration(filePath).TotalSeconds; SoundboardSample NewSoundboardSample = new SoundboardSample(filePath) { GroupName = "Ungrouped", FileTimeMax = totalSeconds, FileTimeMin = 0, FileTimeUpperValue = totalSeconds, FileTimeLowerValue = 0, HotkeyId = SoundboardSampleCollection.Count }; SoundboardSampleCollection.Add(NewSoundboardSample); } catch (Exception ex) { ApplicationLogger.Log(ex.Message, ex.StackTrace); } }