private void Stop_button_Click(object sender, EventArgs e) { try { coverArt.ImageLocation = Environment.CurrentDirectory + "\\AudioWizard.png"; playBox.Items.Clear(); if (IsRecording == false) { currentTime_label.Text = "00:00:00"; outputDevice.Dispose(); foundationReader.Dispose(); foundationReader = null; GC.Collect(); Play_button.Text = "►"; } else { capture.StopRecording(); capture.RecordingStopped += (s, o) => { writer.Dispose(); writer = null; capture.Dispose(); }; IsRecording = false; SFD.Filter = "WAV|*wav"; if (SFD.ShowDialog() == DialogResult.OK) { File.Move(Environment.CurrentDirectory + "\\recording.wav", SFD.FileName + ".wav"); } } } catch { } }
/// <summary> /// Load a song /// </summary> /// <param name="path">the absolute path</param> private void Load(string path) { try { DisposeWaveOut(true); _playStream?.Dispose(); _playStream = new MediaFoundationReader(path); if (_playStream == null) { return; } _waveOutDevice.Init(_playStream); _currentSong.Duration = Convert.ToInt64(_playStream.TotalTime.TotalSeconds); SongChanged?.Invoke(_currentSong); TogglePlay(); } catch (Exception e) { Logger.LogError(e, "MusicPlayer: Could not load song " + path); _playStream = null; if (!_isReceiveMode) { Next(); } } }
public void Dispose() { reader.Dispose(); output.Dispose(); speed.Dispose(); //fft.Dispose(); }
private void musicListPanelsButton_Click(object sender, EventArgs e) { audioPath = fileNames[Convert.ToInt32((sender as System.Windows.Forms.Button).Name)]; if (fileReader == null) { fileReader = new MediaFoundationReader(audioPath); } else { fileReader.Close(); fileReader.Dispose(); fileReader = new MediaFoundationReader(audioPath); } if (outputDevice == null) { outputDevice = new WaveOutEvent(); } else { outputDevice.Stop(); } musicTrackBar.Value = 0; musicIsPlaying = false; playButton.Text = ""; timerOfPlayback.Enabled = false; outputDevice.Init(fileReader); musicTrackBar.Maximum = fileReader.TotalTime.Minutes * 60 + fileReader.TotalTime.Seconds; maximumDuration.Text = fileReader.TotalTime.Minutes.ToString("00") + ":" + fileReader.TotalTime.Seconds.ToString("00"); playButton_Click(null, null); }
private void resetWaveOut() { if (m_mf != null) { m_mf.Dispose(); } m_mf = new MediaFoundationReader(getRadioInfos().url); if (m_wo != null) { m_wo.Dispose(); } m_wo = new WaveOutEvent(); m_wo.Init(m_mf); m_wo.Volume = m_volume; }
public void Stop() { if (waveOut != null) { waveOut.Stop(); waveOut.Dispose(); waveOut = null; } if (baStream != null) { baStream.Dispose(); baStream = null; } if (wavStream != null) { wavStream.Dispose(); wavStream = null; } if (mf != null) { mf.Close(); mf.Dispose(); mf = null; } }
private void OnPlaybackStopped(object sender, StoppedEventArgs e) { if (closing) { wvOut.Dispose(); audioFile.Dispose(); } }
private void ClearPlayer() { _waveOutDevice.Stop(); _mp3Reader.Dispose(); _mp3Reader = null; _waveOutDevice.Dispose(); _waveOutDevice = null; }
private void CloseInStream() { if (reader != null) { reader.Dispose(); reader = null; } }
public static void Stop() { PlayerNotification.Stop(); player?.Stop(); reader?.Dispose(); player?.Dispose(); ViewModelManager.MainWindowViewModel.SetStopState(); }
public void Dispose() { tokenSource?.Cancel(); tokenSource?.Dispose(); tokenSource = null; waveOut?.Dispose(); media?.Dispose(); }
public void Dispose() { dis = true; task?.Wait(); wout.Dispose(); wout = null; reader.Dispose(); reader = null; }
public void Stop() { trackStatus = TrackStatus.Off; SampleRate = 0; synchronizationReader = null; // do not dispose trackReader.Dispose(); trackReader = null; samplesReal = samplesImaginary = null; ClearSpectrumColumns(); }
//If the DirectSound output is running/paused, //stop, set the player to not playing, change the title text, //and clear the current playtime. private void stopButton(object sender, EventArgs e) { if (dsOut.PlaybackState != PlaybackState.Stopped) { dsOut.Stop(); isPlaying = false; mfr.Dispose(); this.Text = "pygmp3"; label1.Text = ""; } }
private void OnPlaybackStopped(object sender, StoppedEventArgs e) { if (e.Exception != null) { //_logger.Exception ("播放出现错误!",e.Exception); } outputDevice?.Dispose(); outputDevice = null; mfr?.Dispose(); mfr = null; }
/// <summary> /// NIE KURWA JEGO MAĆ RUSZAĆ TEGO. CHUJ WIE JAK TO DZIAŁA, ALE ,,U MNIE DZIAŁO" /// </summary> /// <param name="Url"></param> /// <param name="sender"></param> public static void Play(string Url, object sender) { bool PlayingRadio = false; if (woe != null) { woe.Dispose(); } using (var mf = new MediaFoundationReader(Url)) using (var wo = new WaveOutEvent()) { mediaFoundationReader = mf; wo.Init(mf); if (Url.StartsWith("http")) { TrackLength = 0; PlayingRadio = true; UI.UiManager.HideTrackPositionSlider(); } else { UI.UiManager.ShowTrackPositionSlider(); TrackLength = mf.TotalTime.TotalSeconds; } if (Source.Global.RadioInitiated == false) { wo.Volume = 1.0f; Source.Global.RadioInitiated = true; } woe = wo; woe.Play(); while (Source.Global.PlayerTaskPaused == false && wo.PlaybackState == PlaybackState.Playing) { if (!PlayingRadio) { Position = mf.CurrentTime.TotalSeconds; MainWindow.Instance.Dispatcher.Invoke(() => MainWindow.Instance.trackPositionSlider.StartUpdating(Position, TrackLength)); if (wo.PlaybackState != PlaybackState.Playing) { Source.Global.PlayerTaskPaused = true; } } System.Threading.Thread.Sleep(1000); } mf.Dispose(); wo.Dispose(); Source.Global.cancellationTokenSource.Cancel(); } }
protected override void Dispose(bool disposing) { if (!_wma_disposed) { if (disposing) { m_reader.Dispose(); } _wma_disposed = true; base.Dispose(disposing); } }
public void UnloadEpisode() { if (player != null) { player.Dispose(); } if (currentReader != null) { currentReader.Dispose(); } player = null; currentReader = null; }
private void Output_PlaybackStopped(object sender, StoppedEventArgs e) { Dispatcher.BeginInvoke(new Action(() => { Console.WriteLine("Finished"); mfr.Dispose(); mfr = null; BeginB.IsEnabled = true; fftProv.FftFinished -= FftProv_FftFinished; Output.PlaybackStopped -= Output_PlaybackStopped; })); }
public void StopTrack() { if (ActiveTrack != null) { SpectrumVisualizer?.Stop(); waveOut.Dispose(); waveOut = null; trackReader.Dispose(); trackReader = null; ActiveTrack = null; PlaybackState = PlaybackState.StoppedManually; } }
private static String GetDuration(string fileName) { try { MediaFoundationReader wf = new MediaFoundationReader(fileName); String result = MusicPlayer.FormatTimeSpan(wf.TotalTime); wf.Dispose(); return(result); } catch { return("UNKNOW"); } }
public void Close() { InSample = null; OutSample = null; m_fileReader.Dispose(); m_fileReader = null; m_bufferSize = 0; m_blockLength = 0; m_buffer = null; m_bufferPos = 0; IsOpen = false; }
private void PlaySound() { var file = Path.Combine(BasicTeraData.Instance.ResourceDirectory, "sound/", BasicTeraData.Instance.WindowData.NotifySound); if (!File.Exists(file)) { file = BasicTeraData.Instance.WindowData.NotifySound; if (!File.Exists(file)) { return; } } try { //Create Output Stream with Data from Audio File / Network Stream var outputStream = new MediaFoundationReader(file); //Create Volume Stream to control volume of output //ex: volumeStream.Volume = 0.5f; Float between 0 & 1 var volumeStream = new WaveChannel32(outputStream); volumeStream.Volume = BasicTeraData.Instance.WindowData.Volume; //Create WaveOutEvent since it works in Background and UI Threads var player = new WaveOutEvent(); //Init Player with Configured Volume Stream player.Init(volumeStream); player.Play(); var timer = new System.Threading.Timer((obj) => { player.Stop(); player.Dispose(); volumeStream.Dispose(); outputStream.Dispose(); outputStream = null; player = null; volumeStream = null; }, null, BasicTeraData.Instance.WindowData.SoundNotifyDuration, System.Threading.Timeout.Infinite); } catch (Exception e) { // Get stack trace for the exception with source file information var st = new StackTrace(e, true); // Get the top stack frame var frame = st.GetFrame(0); // Get the line number from the stack frame var line = frame.GetFileLineNumber(); BasicTeraData.LogError("Sound ERROR test" + e.Message + Environment.NewLine + e.StackTrace + Environment.NewLine + e.InnerException + Environment.NewLine + e + Environment.NewLine + "filename:" + file + Environment.NewLine + "line:" + line, false, true); } }
private static void CloseWaveOut() { waveOutDevice?.Stop(); if (audioFileReader != null) { audioFileReader.Dispose(); audioFileReader = null; } if (waveOutDevice != null) { waveOutDevice.Dispose(); waveOutDevice = null; } }
/// <summary> /// Disposes this class properly /// </summary> public void Dispose() { try { _disposing = true; DisposeWaveOut(); if (_playstream != null) { _playstream.Dispose(); } } catch { // TODO: fix other thread exception } }
protected override void OnDispose() { if (sampling_timer_ != null) { sampling_timer_.Dispose(); } if (reader_ != null) { reader_.Dispose(); } if (resampler_ != null) { resampler_.Dispose(); } }
private void StopSong() { if (outputDevice != null) { outputDevice.PlaybackStopped -= OutputDevice_PlaybackStopped; //don't fire the event if we're stopping ourselves. outputDevice.Stop(); outputDevice.Dispose(); } if (audioFile != null) { audioFile.CurrentTime = TimeSpan.FromTicks(0); try { audioFile.Dispose(); } catch (Exception) { // don't die if the dispose races - it still succeeds. } } }
public void Play() { var file = System.IO.File.Exists(File) ? File : Path.Combine(BasicTeraData.Instance.ResourceDirectory, "sound/", File); try { var outputStream = new MediaFoundationReader(file); var volumeStream = new WaveChannel32(outputStream) { Volume = Volume }; //Create WaveOutEvent since it works in Background and UI Threads var player = new DirectSoundOut(); //Init Player with Configured Volume Stream player.Init(volumeStream); player.Play(); var timer = new Timer(obj => { player.Stop(); player.Dispose(); volumeStream.Dispose(); outputStream.Dispose(); outputStream = null; player = null; volumeStream = null; }, null, Duration, Timeout.Infinite); } catch (Exception e) { // Get stack trace for the exception with source file information var st = new StackTrace(e, true); // Get the top stack frame var frame = st.GetFrame(0); // Get the line number from the stack frame var line = frame.GetFileLineNumber(); BasicTeraData.LogError( "Sound ERROR test" + e.Message + Environment.NewLine + e.StackTrace + Environment.NewLine + e.InnerException + Environment.NewLine + e + Environment.NewLine + "filename:" + file + Environment.NewLine + "line:" + line, false, true); } }
/// <summary> /// Manually stops the playing sound, or does nothing if the sound is not playing. /// </summary> internal void StopSound() { if (audioFileReader != null || waveOutDevice != null) { // if these vars still have valid contents, then the stop of sound is in process IsBeingStopped = true; } else { // these vars below are anyways set in the other if branch (after `return;` below) IsBeingStopped = false; justNormalPlaybackEnd = true; IsPlaying = false; return; } //ShouldBePlaying = false; justNormalPlaybackEnd = false; //if (volumeStream != null) // volumeStream.Dispose(); if (audioFileReader != null) { audioFileReader.Close(); audioFileReader.Dispose(); audioFileReader = null; } if (waveOutDevice != null) { waveOutDevice.Stop(); waveOutDevice.Dispose(); waveOutDevice = null; } justNormalPlaybackEnd = true; IsPlaying = false; }
public ReusablePlayer(string Path) { FilePath = Path; if (System.IO.File.Exists(Path)) { switch (System.IO.Path.GetExtension(Path.ToLower())) { default: MediaFoundationReader mfr = new MediaFoundationReader(Path); mfr.Position = 0; System.IO.MemoryStream ms = new System.IO.MemoryStream(); ms.Position = 0; mfr.CopyTo(ms); mfr.Dispose(); memory = ms.ToArray(); format = mfr.WaveFormat; ms.Dispose(); break; } } }