Exemple #1
0
        private void DgMemeFiles_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
            {
                if (selectedDevice != Guid.Empty)
                {
                    MemeSound selectedSound = dgMemeFiles.SelectedItem as MemeSound;

                    if (selectedSound != null)
                    {
                        if (defaultDevice == null && audioFileForDefault == null)
                        {
                            defaultDevice = new DirectSoundOut(DirectSoundOut.DSDEVID_DefaultPlayback);
                            defaultDevice.PlaybackStopped += OnDefaultPlaybackStopped;
                            audioFileForDefault            = new AudioFileReader(selectedSound.Path);
                            audioFileForDefault.Volume     = (float)sDefaultVolume.Value / 100.0f;
                            defaultDevice.Init(audioFileForDefault);
                            defaultDevice.Play();
                            UpdateStatusBarText($"Previewing: {selectedSound.Name} (Not Being Transmitted)");
                        }
                        else
                        {
                            defaultDevice.Stop();
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void GlobalHookMouseDown(object sender, MouseEventExtArgs args)
        {
            if (args.Button == (System.Windows.Forms.MouseButtons)mouseButton && navigationKeyDown && selectedDevice == Guid.Empty)
            {
                UpdateStatusBarText("ERROR! Unable to Play - No Output Device Has Been Selected.");
                return;
            }

            MemeSound selectedSound = dgMemeFiles.SelectedItem as MemeSound;

            if (selectedDevice != Guid.Empty)
            {
                // Make Sure a Sound is Actually Selected First
                if (selectedSound != null)
                {
                    if (args.Button == (System.Windows.Forms.MouseButtons)mouseButton && navigationKeyDown)
                    {
                        if (audioFileForOutput != null)
                        {
                            outputDevice.Stop();
                            if (audioFileForDefault != null)
                            {
                                defaultDevice.Stop();
                                return;
                            }
                            return;
                        }
                    }

                    if (args.Button == (System.Windows.Forms.MouseButtons)mouseButton && navigationKeyDown)
                    {
                        if (outputDevice == null)
                        {
                            outputDevice = new DirectSoundOut(selectedDevice);
                            outputDevice.PlaybackStopped += OnOutputPlaybackStopped;
                            if (cbPlayOnDefault.IsChecked.Value && defaultDevice == null)
                            {
                                defaultDevice = new DirectSoundOut(DirectSoundOut.DSDEVID_DefaultPlayback);
                                defaultDevice.PlaybackStopped += OnDefaultPlaybackStopped;
                            }
                        }

                        if (audioFileForOutput == null)
                        {
                            try
                            {
                                audioFileForOutput        = new AudioFileReader(selectedSound.Path);
                                audioFileForOutput.Volume = (float)sOutputVolume.Value / 100.0f;
                                outputDevice.Init(audioFileForOutput);
                                if (cbPlayOnDefault.IsChecked.Value && audioFileForDefault == null)
                                {
                                    audioFileForDefault        = new AudioFileReader(selectedSound.Path);
                                    audioFileForDefault.Volume = (float)sDefaultVolume.Value / 100.0f;
                                    defaultDevice.Init(audioFileForDefault);
                                }
                            } catch (Exception ex) {
                                if (MessageBox.Show($"An error occurred when trying to play {selectedSound.Path}. It has probably been renamed, moved or deleted!\n\nError Message:\n{ex.Message}\n\nDo you wish to delete this file from the list?", "Error", MessageBoxButton.YesNo, MessageBoxImage.Error) == MessageBoxResult.Yes)
                                {
                                    addedFileList.Remove(selectedSound.Path);
                                    memeList.Remove(selectedSound);
                                    Settings.Default.LastFileList = String.Join(";", addedFileList.ToArray());
                                    Settings.Default.Save();
                                    return;
                                }
                                return;
                            }
                        }

                        // Play the Sounds
                        outputDevice.Play();
                        defaultDevice.Play();
                        // Indicate Which Song is Being Played
                        selectedSound.isPlaying = true;
                        UpdateStatusBarText($"Playing {selectedSound.Name}.");
                        // Used for Progress Bar. Probably inaccurate and ineffiecent. Sadly outputDevice.PlaybackPosition causes a TON of lag if used in a while loop.
                        soundPlayStart = DateTime.Now;
                        soundPlayEnd   = DateTime.Now.AddTicks(selectedSound.Length.Ticks);
                        // Simulate PTT
                        if (cbSimulatePTT.IsChecked.Value)
                        {
                            keyboardSimulator.Send((KeyboardSimulator.ScanCodeShort)pttKey);
                        }
                    }
                }
            }
        }