/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } // Dispose stuff here if (Thimble != null) { Thimble.Dispose(); } if (outputDevice != null) { outputDevice.Dispose(); } if (audioReader != null) { audioReader.Dispose(); } if (audioDataStream != null) { audioDataStream.Dispose(); } } base.Dispose(disposing); }
public void Refresh() { if (Wave != null) { Wave.PlaybackStopped -= Wave_PlaybackStopped; Wave.Stop(); Wave.Dispose(); } if (Audio != null) { Audio.Dispose(); } Wave = null; Audio = null; Wave = new WaveOutEvent(); Wave.PlaybackStopped += Wave_PlaybackStopped; IsEnabled = false; Preview.Source = null; SongPosition.Value = 0; SongLength.Text = "00:00"; TextPosition.Text = "00:00"; SongName.Text = "Песня"; IsDrag = false; IsPause = true; PlayIcon.Kind = MaterialDesignThemes.Wpf.PackIconKind.Play; }
private void StopAndCloseStream() { if (waveOutDevice != null) { waveOutDevice.Stop(); waveOutDevice.Dispose(); } if (activeStream != null) { ActiveStream.Close(); ActiveStream.Dispose(); ActiveStream = null; } if (waveOutDevice != null) { waveOutDevice.Dispose(); waveOutDevice = null; } if (inputStream != null) { inputStream.Close(); inputStream.Dispose(); inputStream = null; } }
public void StartStopSineWave() { errMsg = null; try { if (driverOut.PlaybackState == PlaybackState.Playing) { driverOut.Stop(); } else { driverOut.Dispose(); driverOut = new WaveOutEvent { DeviceNumber = DeviceNumber }; driverOut.Init(sg); driverOut.Play(); } } catch (Exception ex) { errMsg = ex.Message; #pragma warning disable CA1303 // Do not pass literals as localized parameters throw new Exception("Audio StartStopSineWave failed"); #pragma warning restore CA1303 // Do not pass literals as localized parameters } }
private void OnSelectedEpisodeChanged(object sender, TreeViewEventArgs e) { if (player != null) { player.Dispose(); } player = null; var selectedEpisode = subscriptionView.treeViewPodcasts.SelectedNode.Tag as Episode; if (selectedEpisode != null) { splitContainer1.Panel2.Controls.Clear(); splitContainer1.Panel2.Controls.Add(episodeView); SaveEpisode(); currentEpisode = selectedEpisode; episodeView.labelEpisodeTitle.Text = currentEpisode.Title; episodeView.labelPublicationDate.Text = currentEpisode.PubDate; episodeView.labelDescription.Text = currentEpisode.Description; buttonFavourite.Checked = currentEpisode.IsFavourite; currentEpisode.IsNew = false; episodeView.numericUpDownRating.Value = currentEpisode.Rating; episodeView.textBoxTags.Text = String.Join(",", currentEpisode.Tags ?? new string[0]); episodeView.textBoxNotes.Text = currentEpisode.Notes ?? ""; } var selectedPodcast = subscriptionView.treeViewPodcasts.SelectedNode.Tag as Podcast; if (selectedPodcast != null) { splitContainer1.Panel2.Controls.Clear(); splitContainer1.Panel2.Controls.Add(podcastView); podcastView.SetPodcast(selectedPodcast); } }
private static void Output_PlaybackStopped(object sender, StoppedEventArgs e) { output.Stop(); output.Dispose(); output.Dispose(); wav.Dispose(); }
//Stop without next song public bool stopSound() { PlaybackStopType = PlaybackStopTypes.PlaybackStoppedByUser; if (playing) { outputDevice?.Dispose(); outputDevice = null; try { audioFile?.Dispose(); } catch (Exception ex) { Debug.Print("exception: " + ex.ToString()); } audioFile = null; playing = false; return(true); } else { outputDevice?.Stop(); audioFile?.Dispose(); audioFile = null; return(false); } }
private void BtnDump_Click(object sender, EventArgs e) { outputDevice.Dispose(); outputDevice = null; audioFile.Dispose(); audioFile = null; }
public void UnloadEpisode() { if (player != null) { player.Dispose(); } player = null; }
public void UnloadEpisode() { if (_player != null) { _player.Dispose(); } _player = null; _currentReader = null; }
private void __INTERNAL_ChangeRate() { _WaveOut.Stop(); _WaveOut.Dispose(); _WaveOut = null; _BPCMWaveProvider = null; GC.Collect(); __INTERNAL_WaveOutInit(); }
public void Load(string filename) { _player?.Stop(); _player?.Dispose(); _reader?.Dispose(); _reader = new AudioFileReader(filename); _player = new WaveOutEvent(); _player.Init(this); }
// 音声フィアルを開く private void openAudioFileToolStripMenuItem_Click(object sender, EventArgs e) { // フォルダーMYMusicにある音声ファイルを開く openVoiceFileDialog.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); //openFileDialog1がイニシャルでMyMusicを開くようにデフォルトで設定 openVoiceFileDialog.Filter = "Voice_file(*.mp3;*.wav)|*.mp3;*.wav|MPEG_Layer-3_file(*.mp3)|*.mp3|wave_file(*.wav" + ")|*.wav"; //音声ファイルのフィルタ if (openVoiceFileDialog.ShowDialog() == DialogResult.OK) { if (audioFile != null)//再生中に音声ファイルを選択できてしまい、多重再生できてしまうための対策。再生中に新しいファイルを選んだときは、再生を停止し、デバイスとファイルをdisposeする。(初期設定) { outputDevice.Stop(); outputDevice.Dispose(); outputDevice = null; audioFile.Dispose(); audioFile = null; } voiceFilePath = openVoiceFileDialog.FileName; voiceFileBaseName = Path.GetFileNameWithoutExtension(voiceFilePath); voiceFileDirectory = Path.GetDirectoryName(voiceFilePath); // Label1のファイル名の表示の処理:ファイル名が長すぎるときに、label1の表示部分が赤くなるのを防ぐ処理(拡張子を含むFileNameが24文字以上の時、ファイル名のベース部分を切り出し、10文字目に~~記号を挿入し、ベース部分の後ろから10を加え、置き換える string fileNameLabel1 = Path.GetFileName(voiceFilePath); if (fileNameLabel1.Length > 24) { fileNameLabel1 = fileNameLabel1.Substring(0, 10) + "~~" + fileNameLabel1.Substring(fileNameLabel1.IndexOf(".") - 10, 10) + Path.GetExtension(voiceFilePath); } label1.Text = fileNameLabel1; currentPosition = 0; outputDevice = new WaveOutEvent(); audioFile = new AudioFileReader(voiceFilePath); audioFile.Position = currentPosition; outputDevice.Init(audioFile); playButton.Image = Properties.Resources.play100_100; //必要な値を求める bytePerSec = audioFile.WaveFormat.BitsPerSample / 8 * audioFile.WaveFormat.SampleRate * audioFile.WaveFormat.Channels; length = (int)audioFile.Length / bytePerSec; } label3.Text = new TimeSpan(0, 0, length).ToString(); //音源の長さ(時間)を表示 // STSファイルを開く準備 openSTSFileDialog.FileName = voiceFileDirectory + "\\" + voiceFileBaseName + ".sts"; openSTSFile(openSTSFileDialog); // stsファイルを開く }
/** * Pause the current song and start playing the selected song. */ private void TrackListIndexChanged(object sender, EventArgs e) { if (waveOutEvent != null) { if (waveOutEvent.PlaybackState == PlaybackState.Playing) { waveOutEvent.Pause(); waveOutEvent = new WaveOutEvent(); } if (trackList.SelectedItems.Count > 0) { string item = trackList.SelectedItems[0].Text; foreach (Track track in tracks) { if (item == track.Title) { if (waveOutEvent.PlaybackState == PlaybackState.Playing) { waveOutEvent.Pause(); buttonPlay.Image = Image.FromFile("iconPlay.png"); if (threadTrackCurrent.ThreadState == ThreadState.Running) { threadTimeCurrent.Abort(); threadSeekBar.Abort(); threadTrackCurrent.Abort(); } } else if (waveOutEvent.PlaybackState == PlaybackState.Paused) { if (threadTrackCurrent.ThreadState == ThreadState.Aborted || threadTrackCurrent.ThreadState == ThreadState.Suspended) { threadTrackCurrent.Start(); threadSeekBar.Start(); threadTimeCurrent.Start(); } waveOutEvent.Play(); buttonPlay.Image = Image.FromFile("iconPause2.png"); } waveOutEvent.Dispose(); waveOutEvent = null; trackCurrent = null; trackCurrent = new Track(); trackCurrent.File = track.File; trackCurrent.Path = track.Path; trackCurrent.getMetaDataTrack(); PlayMusic(); } } } } }
public void Init(ISampleProvider sampleProvider) { lock (lockObj) { if (waveOutEvent != null) { waveOutEvent.Stop(); waveOutEvent.Dispose(); } waveOutEvent = new WaveOutEvent() { DeviceNumber = deviceNumber, }; waveOutEvent.Init(sampleProvider); } }
/// <summary> /// Plays the specified stream. /// </summary> /// <param name="stream">The stream.</param> /// <param name="volume">The volume.</param> private WaveOutEvent Play(Stream stream, float volume) { try { var waveOut = new WaveOutEvent(); var mp3Reader = new Mp3FileReader(stream); waveOut.Init(mp3Reader); waveOut.Volume = volume; if (this._currentSound != null) { this._currentSound.Stop(); this._currentSound = null; } this._currentSound = waveOut; waveOut.Play(); EventHandler <StoppedEventArgs> handler = default; handler = (object s, StoppedEventArgs e) => { stream.Dispose(); mp3Reader.Dispose(); waveOut.Dispose(); waveOut.PlaybackStopped -= handler; }; waveOut.PlaybackStopped += handler; return(waveOut); } catch { return(null); } }
private void OnPlaybackStopped(object sender, StoppedEventArgs args) { outputDevice.Dispose(); outputDevice = null; audioFile.Dispose(); audioFile = null; }
/// <summary> /// Plays the alert. /// </summary> private void PlayAlert() { try { var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Lurker.UI.Assets.TradeAlert.mp3"); var waveOut = new WaveOutEvent(); var mp3Reader = new Mp3FileReader(stream); waveOut.Init(mp3Reader); waveOut.Volume = this._settingsService.AlertVolume; waveOut.Play(); EventHandler <StoppedEventArgs> handler = default; handler = (object s, StoppedEventArgs e) => { stream.Dispose(); mp3Reader.Dispose(); waveOut.Dispose(); waveOut.PlaybackStopped -= handler; }; waveOut.PlaybackStopped += handler; } catch { } }
private void OnPlaybackStopped(object sender, StoppedEventArgs stopArgs) { m_audioDevice.Dispose(); m_audioDevice = null; m_audioFile.Dispose(); m_audioFile = null; }
/// <summary> /// Plays the specified stream. /// </summary> /// <param name="stream">The stream.</param> /// <param name="volume">The volume.</param> private void Play(Stream stream, float volume) { try { var waveOut = new WaveOutEvent(); var mp3Reader = new Mp3FileReader(stream); waveOut.Init(mp3Reader); waveOut.Volume = volume; waveOut.Play(); EventHandler <StoppedEventArgs> handler = default; handler = (object s, StoppedEventArgs e) => { stream.Dispose(); mp3Reader.Dispose(); waveOut.Dispose(); waveOut.PlaybackStopped -= handler; }; waveOut.PlaybackStopped += handler; } catch { } }
private void OnPlaybackStopped(object sender, StoppedEventArgs args) //Clear audio ting ting, Forstår det ikke helt men det skal være der { outputDevice.Dispose(); outputDevice = null; audioFile.Dispose(); audioFile = null; }
private void Output_PlaybackStopped(object sender, StoppedEventArgs e) { reader.Dispose(); output.Dispose(); //Aqui es donde seria mas prudente detener el timer porque lo haria al terminar lo que se guarda en el ultimo buffer timer.Stop(); }
public void Stop() { try { _timer.Enabled = false; _timer.Dispose(); _playbackState = StreamingPlaybackState.Stopped; if (_waveOut != null) { _waveOut.Stop(); _waveOut.Dispose(); _waveOut = null; } if (_bufferThread != null && _bufferThread.IsAlive) { _bufferThread.Join(1000); } } catch (Exception e) { _log.Log("Grooveshark: Error while stopping player. " + e.Message, Category.Info, Priority.Medium); } finally { _isPlaying(false); _elapsedTimeSpan = TimeSpan.Zero; } }
private void Timer_Tick(object sender, EventArgs e) { currentSecond = (int)mp3Reader.CurrentTime.TotalSeconds; lblRealTime.Text = mp3Reader.CurrentTime.ToString("hh':'mm':'ss"); if (currentSecond >= timeEnd) { btnPlay.Visible = true; btnStop.Visible = false; waveOut.Stop(); mp3Reader.Position = 0; mp3Reader.Dispose(); waveOut.Dispose(); timer.Stop(); } }
private void AlarmWindow_Closed(object sender, EventArgs e) { IsClosed = true; device.Stop(); file.Dispose(); device.Dispose(); }
private void BtnPlay_Click(object sender, EventArgs e) { if (!File.Exists($"{Trimmed}/{CurrentFile}")) { MessageBox.Show("No recording"); return; } btnPlay.Enabled = false; using (WaveStream mainOutputStream = new WaveFileReader($"{Trimmed}/{CurrentFile}")) { using (WaveChannel32 volumeStream = new WaveChannel32(mainOutputStream)) { volumeStream.PadWithZeroes = false; using (WaveOutEvent player = new WaveOutEvent()) { player.Init(volumeStream); player.Play(); while (player.PlaybackState == PlaybackState.Playing) { Thread.Sleep(1); } player.Dispose(); } } } btnPlay.Enabled = true; }
private void Application_Exit(object sender, ExitEventArgs e) { SaveProfile(); outputDevice.Dispose(); outputDevice = null; }
private void playStoped(object sender, StoppedEventArgs e) { player.Stop(); player.Dispose(); volumeStream.Close(); Console.WriteLine("a"); }
public void StopMusic() { if (playing) { try { outputDevice.Dispose(); outputDevice = null; audioFile?.Dispose(); audioFile = null; playing = false; nowplaying.Text = "Nothing"; position = 0; label5.Text = "(nothing playing)"; moreinfo.Visible = false; Text = "FRESHMusicPlayer (For Weebs)"; if (playlistmode) { //PlayPlaylist(); } } catch (System.NullReferenceException) { //PlayMusic(filePath); } }
public void Play(UProject project) { if (renderTask != null) { if (renderTask.IsCompleted) { renderTask = null; } else { return; } } if (outDevice != null) { if (outDevice.PlaybackState == PlaybackState.Playing) { return; } if (outDevice.PlaybackState == PlaybackState.Paused) { outDevice.Play(); return; } outDevice.Dispose(); } Render(project); }