コード例 #1
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);
     }
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Moczarski/MP3PlayerCSharp
 private void nextButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (!loop && !playlistLoop && !random)
         {
             outputDevice?.Stop();
         }
         if (playlist.SelectedIndex < playlist.Items.Count - 1)
         {
             playlist.SelectedIndex = playlist.SelectedIndex + 1;
         }
         else if (playlist.SelectedIndex == playlist.Items.Count - 1)
         {
             playlist.SelectedIndex = 0;
         }
         if (playlist.SelectedItem != null)
         {
             filepath.Text = playlist.SelectedItem.ToString();
             if (!loop || !random)
             {
                 playAsync_Click(sender, e);
             }
         }
     }
     catch (Exception ex)
     {
         toolStripLabel.Text = "Problem z następnym - " + ex.ToString();
     }
 }
コード例 #3
0
        public void Load(string filename)
        {
            _player?.Stop();
            _player?.Dispose();
            _reader?.Dispose();

            _reader = new AudioFileReader(filename);
            _player = new WaveOutEvent();
            _player.Init(this);
        }
コード例 #4
0
 //stop button, executes stop function(OnPlayBackStopped).
 public void OnButtonStopClick()
 {
     outputDevice?.Pause();
     outputDevice?.Stop();
     DisposeOfSong();
     audioFile = null;
     isPlaying = false;
     if (_CurrentSong != null)
     {
         MusicQueue.AddSongToPreviousQueue(_CurrentSong);
     }
 }
コード例 #5
0
ファイル: Audio.cs プロジェクト: hnjm/CChat2
        public static void ClearAll()
        {
            if (!Initialized)
            {
                Main.Log("[AUDIO] Not initialized, cannot clear all!");
                return;
            }

            foreach (var item in Providers)
            {
                item.Value.ClearBuffer();
            }
            Providers.Clear();
            IDs.Clear();
            Mixer.RemoveAllMixerInputs();
            Output.Stop();
            Input.StopRecording();

            Mixer  = null;
            Output = null;
            Input  = null;
            maxID  = 0;

            Initialized = false;
            Main.Log("[AUDIO] Cleared all data, reset.");
        }
コード例 #6
0
 public override void ButtonHandler(bool value)
 {
     if (value)
     {
         try
         {
             player.DeviceNumber      = deviceIndex;
             audioFileStream.Position = 0;
             player.Play();
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex);
         }
     }
     else
     {
         try
         {
             player.Stop();
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex);
         }
     }
 }
コード例 #7
0
 public void DisposeScene()
 {
     keepPlaying = false;
     OutputDevice.Stop();
     OutputDevice.PlaybackStopped -= SongStopped;
     audioFile.Seek(0, System.IO.SeekOrigin.Begin);
 }
コード例 #8
0
 public static void Stop()
 {
     if (CurrentlyPlaying)
     {
         _device.Stop();
     }
 }
コード例 #9
0
 /// <summary>
 /// Stops replay
 /// </summary>
 public void StopReplay()
 {
     if (_wav != null)
     {
         _wav.Stop();
     }
 }
コード例 #10
0
        private void button6_Click(object sender, EventArgs e)
        {
            try
            {
                string filename = MyList.SearchToNext(listBox1.SelectedItem.ToString());
                try
                {
                    listBox1.SelectedIndex += 1;


                    outputDevice.Dispose();
                    outputDevice = new WaveOutEvent();
                    audioFile    = new AudioFileReader(filename);
                    outputDevice.Init(audioFile);
                    songtrack.Maximum = (int)audioFile.TotalTime.TotalSeconds;
                    songtrack.Value   = 0;


                    outputDevice.Play();
                    timer1.Start();
                }
                catch (ArgumentOutOfRangeException)
                {
                    outputDevice.Stop();
                    outputDevice.Dispose();
                    pictureBox2.Visible = true;

                    return;
                }
            }
            catch (NullReferenceException) { }
        }
コード例 #11
0
 public void PlaySound(string filename)
 {
     if (m_player.PlaybackState != PlaybackState.Stopped)
     {
         m_delayedAction = () => PlaySound(filename);
         m_player.Stop();
     }
     else
     {
         m_audioFile = new AudioFileReader("Library\\" + filename);
         //m_audioFile.Skip();
         m_player.Init(m_audioFile);
         m_player.Play();
         m_delayedAction = null;
     }
 }
コード例 #12
0
 private void OnButtonStopClick(object sender, EventArgs e)
 {
     if (player != null)
     {
         player.Stop();
     }
 }
コード例 #13
0
        public void PlayOneSong()
        {
            AudioFileReader audioFile    = null;
            WaveOutEvent    outputDevice = null;

            try
            {
                string audioFilePath = @"C:\Users\DJTom\OneDrive\Plocha\20201007_hodina\SongsAndVotesSol\Resources\Peter_Nemec_-_Future_Life_OFFICIAL_LYRICS_VIDEO_1.mp3";
                audioFile    = new AudioFileReader(audioFilePath);
                outputDevice = new WaveOutEvent();

                outputDevice.Init(audioFile);
                outputDevice.Play();

                Console.ReadKey(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadKey(true);
            }
            finally
            {
                if (outputDevice != null)
                {
                    outputDevice.Stop();
                    outputDevice.Dispose();
                }
                if (audioFile != null)
                {
                    audioFile.Close();
                    audioFile.Dispose();
                }
            }
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: MiklosPathy/TrackConv
        private void SynthThread()
        {
            WaveOutEvent _waveOutEvent = new WaveOutEvent();

            _waveOutEvent.DeviceNumber    = -1;
            _waveOutEvent.DesiredLatency  = DesiredLatency;
            _waveOutEvent.NumberOfBuffers = 2;
            _waveOutEvent.Init(this);
            _waveOutEvent.Play();

            while (true)
            {
                if (_waveOutEvent.DesiredLatency != DesiredLatency)
                {
                    _waveOutEvent.Stop();
                    while (_waveOutEvent.PlaybackState != PlaybackState.Stopped)
                    {
                        Thread.Sleep(10);
                    }
                    _waveOutEvent.DesiredLatency = DesiredLatency;
                    _waveOutEvent.Init(this);
                    _waveOutEvent.Play();
                }
                Thread.Sleep(1);
            }
        }
コード例 #15
0
ファイル: SoundPlayer.cs プロジェクト: sycomix/Venus.AI
 private static void Output_PlaybackStopped(object sender, StoppedEventArgs e)
 {
     output.Stop();
     output.Dispose();
     output.Dispose();
     wav.Dispose();
 }
コード例 #16
0
        private static void PlayOnDevice(string fileName, int device)
        {
            var waveOut = new WaveOutEvent();

            waveOut.DeviceNumber = device;

            WaveStream reader;

            if (fileName.EndsWith("mp3"))
            {
                reader = new Mp3FileReader(fileName);
            }
            else
            {
                reader = new WaveFileReader(fileName);
            }

            waveOut.Init(reader);
            waveOut.Play();

            while (waveOut.PlaybackState != PlaybackState.Stopped)
            {
                Thread.Sleep(20);
            }

            waveOut.Stop();

            reader.Dispose();
            waveOut.Dispose();
        }
コード例 #17
0
ファイル: MainWindow.xaml.cs プロジェクト: SDellaoui/Nodio
 private void btnStopSound_Click(object sender, RoutedEventArgs e)
 {
     if (outputDevice != null)
     {
         outputDevice.Stop();
     }
 }
コード例 #18
0
        public void Stop()
        {
            _outputDevice.Stop();

            //Reset Audio file to beginning
            _audioFile.CurrentTime = new TimeSpan(0, 0, 0);
        }
コード例 #19
0
 /// <summary>
 /// NIE KURWA JEGO MAĆ RUSZAĆ TEGO. CHUJ WIE JAK TO DZIAŁA, ALE ,,U MNIE DZIAŁO"
 /// </summary>
 public static void Stop()
 {
     woe.Stop();
     Source.Global.PlayerTaskPaused  = true;
     Source.Global.PlaysMusic        = false;
     Source.Global.PlayerTaskStopped = true;
 }
コード例 #20
0
 private void btnDetener_Click(object sender, RoutedEventArgs e)
 {
     output.Stop();
     btnReproducir.IsEnabled = true;
     btnPausa.IsEnabled      = false;
     btnDetener.IsEnabled    = false;
 }
コード例 #21
0
 public void Stop()
 {
     if (player != null)
     {
         player.Stop();
     }
 }
コード例 #22
0
        public void API(string filePath)
        {
            AudioFileReader audioFile    = null;
            WaveOutEvent    outputDevice = null;

            try
            {
                audioFile    = new AudioFileReader(filePath);
                outputDevice = new WaveOutEvent();

                outputDevice.Init(audioFile);
                outputDevice.Play();

                Console.ReadKey(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                outputDevice.Stop();
                outputDevice.Dispose();
                audioFile.Close();
                audioFile.Dispose();
            }
        }
コード例 #23
0
ファイル: AudioFilter.cs プロジェクト: hotwhitewind/WebCamMod
 public void StopAudio()
 {
     if (_waveOut != null && _mp3Reader != null)
     {
         _waveOut.Stop();
     }
 }
コード例 #24
0
        static void Main()
        {
            var player = new WaveOutEvent {
                NumberOfBuffers = 2,
                DesiredLatency  = 100,
            };
            var trombone = new PinkTromboneSampleProvider(sampleRate: 48000);

            player.Init(trombone);

            player.Play();

            for (int tone = 0; tone < 24; tone++)
            {
                trombone.Thrombone.SetMusicalNote(tone);
                Thread.Sleep(300);
            }
            for (int tone = 22; tone >= 0; tone--)
            {
                trombone.Thrombone.SetMusicalNote(tone);
                Thread.Sleep(300);
            }

            Console.WriteLine("Press any key to stop");
            Console.ReadKey();

            player.Stop();
        }
コード例 #25
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();
            }
        }
コード例 #26
0
 public void Play(byte[] buffer)
 {
     if (waveOutEvent == null)
     {
         waveOutEvent = new WaveOutEvent();
         waveOutEvent.DeviceNumber     = deviceNumber;
         waveOutEvent.PlaybackStopped += playbackStopped;
     }
     else
     {
         waveOutEvent.Stop();
     }
     waveOutEvent.Init(new RawSourceWaveStream(new MemoryStream(buffer), new WaveFormat(44100, WaveOut.GetCapabilities(waveOutEvent.DeviceNumber).Channels)));
     waveOutEvent.Volume = 1;
     waveOutEvent.Play();
 }
コード例 #27
0
 public void StopPlayback()
 {
     if (outDevice != null)
     {
         outDevice.Stop();
     }
 }
コード例 #28
0
 private void disposes()
 {
     try
     {
         track.Text      = "";
         artist.Text     = "";
         year.Text       = "";
         album.Text      = "";
         label6.Text     = "";
         cover.Image     = null;
         trackBar1.Value = 0;
         label2.Text     = "00:00";
         label3.Text     = "00:00";
         if (sound != null)
         {
             sound.Stop();
             sound.Dispose();
             sound = null;
         }
         if (rd != null)
         {
             rd.Dispose();
             rd = null;
         }
         if (reader != null)
         {
             reader.Dispose();
             reader = null;
         }
     }
     catch (Exception) { }
 }
コード例 #29
0
        /// <summary>
        /// Closes the session.
        /// </summary>
        /// <param name="reason">Reason for the closure.</param>
        public override void Close(string reason)
        {
            if (!_isClosed)
            {
                _isClosed = true;

                base.OnRtpPacketReceived -= RtpPacketReceived;

                _waveOutEvent?.Stop();

                if (_waveInEvent != null)
                {
                    _waveInEvent.DataAvailable -= LocalAudioSampleAvailable;
                    _waveInEvent.StopRecording();
                }

                _audioStreamTimer?.Dispose();

                if (_testPatternVideoSource != null)
                {
                    _testPatternVideoSource.SampleReady -= LocalVideoSampleAvailable;
                    _testPatternVideoSource.Stop();
                    _testPatternVideoSource.Dispose();
                }

                // The VPX encoder is a memory hog.
                _vpxDecoder.Dispose();
                _imgConverter.Dispose();

                _vpxEncoder?.Dispose();
                _imgEncConverter?.Dispose();

                base.Close(reason);
            }
        }
コード例 #30
0
        //Create a disposable Sound Player
        void PlaySound()
        {
            using (WaveOutEvent tempWave = new WaveOutEvent())
            {
                tempWave.DeviceNumber = outputDeviceID; //Set the Output Device
                WaveFileReader reader = null;
                reader = new WaveFileReader(filepath);
                WaveChannel32 inputStream = new WaveChannel32(reader);
                inputStream.PadWithZeroes = false;
                tempWave.Init(reader);
                tempWave.Volume = volume;
                tempWave.Play();

                while (tempWave.PlaybackState != PlaybackState.Stopped)
                {
                    //Wait and continue when finished
                    if (stop)
                    {
                        tempWave.Stop();
                    }
                }

                AudioMixer.RemoveSpeaker(this); //Remove Speaker from lists
                reader.Dispose();               //Dispose reader
                tempWave.Dispose();             //Dispose wave

                if (deleteFile)                 //Delete file if deleteFile is true
                {
                    File.Delete(filepath);      //Delete used and created file
                }
            }
        }