コード例 #1
0
        /// <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);
        }
コード例 #2
0
 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;
 }
コード例 #3
0
 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;
     }
 }
コード例 #4
0
ファイル: Audio.cs プロジェクト: mdblack98/TunerUtil
        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
            }
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
ファイル: SoundPlayer.cs プロジェクト: sycomix/Venus.AI
 private static void Output_PlaybackStopped(object sender, StoppedEventArgs e)
 {
     output.Stop();
     output.Dispose();
     output.Dispose();
     wav.Dispose();
 }
コード例 #7
0
ファイル: NAudio.cs プロジェクト: adlerpoland/YMP
 //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);
     }
 }
コード例 #8
0
 private void BtnDump_Click(object sender, EventArgs e)
 {
     outputDevice.Dispose();
     outputDevice = null;
     audioFile.Dispose();
     audioFile = null;
 }
コード例 #9
0
 public void UnloadEpisode()
 {
     if (player != null)
     {
         player.Dispose();
     }
     player = null;
 }
コード例 #10
0
 public void UnloadEpisode()
 {
     if (_player != null)
     {
         _player.Dispose();
     }
     _player        = null;
     _currentReader = null;
 }
コード例 #11
0
ファイル: BPCM.cs プロジェクト: KyodaiKen/BPCM2
 private void __INTERNAL_ChangeRate()
 {
     _WaveOut.Stop();
     _WaveOut.Dispose();
     _WaveOut          = null;
     _BPCMWaveProvider = null;
     GC.Collect();
     __INTERNAL_WaveOutInit();
 }
コード例 #12
0
        public void Load(string filename)
        {
            _player?.Stop();
            _player?.Dispose();
            _reader?.Dispose();

            _reader = new AudioFileReader(filename);
            _player = new WaveOutEvent();
            _player.Init(this);
        }
コード例 #13
0
        // 音声フィアルを開く

        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ファイルを開く
        }
コード例 #14
0
ファイル: MusicPlayer.cs プロジェクト: ccpu/music-player
        /**
         * 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();
                        }
                    }
                }
            }
        }
コード例 #15
0
 public void Init(ISampleProvider sampleProvider)
 {
     lock (lockObj) {
         if (waveOutEvent != null)
         {
             waveOutEvent.Stop();
             waveOutEvent.Dispose();
         }
         waveOutEvent = new WaveOutEvent()
         {
             DeviceNumber = deviceNumber,
         };
         waveOutEvent.Init(sampleProvider);
     }
 }
コード例 #16
0
        /// <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);
            }
        }
コード例 #17
0
 private void OnPlaybackStopped(object sender, StoppedEventArgs args)
 {
     outputDevice.Dispose();
     outputDevice = null;
     audioFile.Dispose();
     audioFile = null;
 }
コード例 #18
0
        /// <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
            {
            }
        }
コード例 #19
0
 private void OnPlaybackStopped(object sender, StoppedEventArgs stopArgs)
 {
     m_audioDevice.Dispose();
     m_audioDevice = null;
     m_audioFile.Dispose();
     m_audioFile = null;
 }
コード例 #20
0
ファイル: SoundService.cs プロジェクト: Z0ld3n/Poe-Lurker
        /// <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
            {
            }
        }
コード例 #21
0
 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;
 }
コード例 #22
0
 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();
 }
コード例 #23
0
        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;
            }
        }
コード例 #24
0
        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();
            }
        }
コード例 #25
0
 private void AlarmWindow_Closed(object sender, EventArgs e)
 {
     IsClosed = true;
     device.Stop();
     file.Dispose();
     device.Dispose();
 }
コード例 #26
0
ファイル: Form1.cs プロジェクト: jmasterx/TextToSpeech
        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;
        }
コード例 #27
0
        private void Application_Exit(object sender, ExitEventArgs e)
        {
            SaveProfile();

            outputDevice.Dispose();
            outputDevice = null;
        }
コード例 #28
0
 private void playStoped(object sender, StoppedEventArgs e)
 {
     player.Stop();
     player.Dispose();
     volumeStream.Close();
     Console.WriteLine("a");
 }
コード例 #29
0
        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);
                }
            }
コード例 #30
0
 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);
 }