Exemple #1
0
        public void Play(Model.Song song)
        {
            if (song == null)
            {
                return;
            }

            if (audioFileReader != null)
            {
                audioFileReader.Dispose();
                audioFileReader = null;
            }

            var t = Mp3Frame.LoadFromStream(null);

            NAudio.Wave.AcmMp3FrameDecompressor dec = new AcmMp3FrameDecompressor(new Mp3WaveFormat(t.SampleRate, 2, t.FrameLength, t.BitRate));



            audioFileReader = new AudioFileReader(song.mp3Url);
            if (waveOutDevice != null)
            {
                waveOutDevice.Stop();
                waveOutDevice.Dispose();
                waveOutDevice = null;
            }

            waveOutDevice = new WaveOut();
            waveOutDevice.Init(audioFileReader);
            waveOutDevice.Play();
        }
Exemple #2
0
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_dsOne != null)
            {
                afrOne.Dispose();
                loopOne.Dispose();
                _dsOne.Dispose();
            }
            if (_dsTwo != null)
            {
                afrTwo.Dispose();
                loopTwo.Dispose();
                _dsTwo.Dispose();
            }
            if (driverOut != null)
            {
                driverOut.Dispose();
            }
            //if (_WaveOutEventOne != null)
            //{
            //    _WaveOutEventOne.Dispose();
            //    _WaveOutEventOne = null;
            //}

            //if (_WaveOutEventTwo != null)
            //{
            //    _WaveOutEventTwo.Dispose();
            //    _WaveOutEventTwo = null;
            //}
        }
Exemple #3
0
 void DestroyPlayer()
 {
     if (HasPlayer)
     {
         wavePlayer.Dispose(); wavePlayer = null;
     }
 }
Exemple #4
0
        public void Play(string file)
        {
            if (File.Exists(file))
            {
                getExtension(file);
                currentFile = file;

                if (isMp3 == true)
                {
                    mp3FileReader             = new Mp3FileReader(file);
                    mp3FileReader.CurrentTime = TimeSpan.FromSeconds(currentPositon);
                    MusicPlayer.Dispose();
                    MusicPlayer.Init(mp3FileReader);
                    MusicPlayer.Play();
                }
                else
                {
                    audioFileReader             = new AudioFileReader(file);
                    audioFileReader.CurrentTime = TimeSpan.FromSeconds(currentPositon);
                    MusicPlayer.Dispose();
                    MusicPlayer.Init(audioFileReader);
                    MusicPlayer.Play();
                }
            }
        }
Exemple #5
0
 private void wavePlayer_PlaybackStopped(object sender, StoppedEventArgs e)
 {
     if (wavePlayer != null)
     {
         wavePlayer.Stop(); wavePlayer.Dispose(); wavePlayer = null;
     }
 }
Exemple #6
0
 private void button5_Click(object sender, EventArgs e)
 {
     player.Dispose();
     i   = i + 1;
     AFR = new AudioFileReader(list[i]);
     player.Init(AFR);
     player.Play();
 }
Exemple #7
0
 public void StopSound()
 {
     if (wavePlayerSounds != null)
     {
         wavePlayerSounds.Stop();
         wavePlayerSounds.Dispose();
         wavePlayerSounds = null;
     }
 }
        public void Reset()
        {
            player?.Dispose();
            player = null;
            recorder?.Dispose();
            recorder = null;

            Recorder_Load(this, new EventArgs());
        }
Exemple #9
0
        public void StopSong()
        {
            wavePlayer?.Stop();

            if (wavePlayer != null)
            {
                wavePlayer?.Dispose();
                wavePlayer = null;
            }
        }
 private void OnDisposed(object sender, EventArgs eventArgs)
 {
     if (wavePlayer != null)
     {
         wavePlayer.Dispose();
         wavePlayer = null;
     }
     if (reader != null)
     {
         reader.Dispose();
         reader = null;
     }
 }
Exemple #11
0
 /// <summary>
 /// Load a stream.
 /// </summary>
 /// <param name="s">The sound file.</param>
 public void LoadStream(SoundFile s)
 {
     Riff = new RiffWave();
     Riff.FromOtherStreamFile(s);
     MemoryStream   = new MemoryStream(Riff.Write());
     WaveFileReader = new WaveFileReader(MemoryStream);
     SoundOut.Dispose();
     SoundOut   = new WaveOut();
     LoopStream = new LoopStream(this, WaveFileReader, Riff.Loops && Loop, s.LoopStart, (Riff.Loops && Loop) ? s.LoopEnd : (uint)s.Audio.NumSamples);
     try {
         SoundOut.Init(LoopStream);
     } catch (NAudio.MmException e) { SoundOut = new NullWavePlayer(); }
 }
Exemple #12
0
 private void mainWindow_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (_audioFileReader != null)
     {
         _audioFileReader.Dispose();
         _audioFileReader = null;
     }
     if (_waveOutDevice != null)
     {
         _waveOutDevice.Dispose();
         _waveOutDevice = null;
     }
 }
Exemple #13
0
    public void OnSongEnd()
    {
        if (started)
        {
            mWaveOutDevice.Stop();
            mWaveOutDevice.Dispose();
        }
        mWaveOutDevice = new WaveOut();
        var song = GetRandomSong();

        mWaveOutDevice = LoadAudioFromData(Environment.GetAudio(Environment.GetAsset(song)), mWaveOutDevice as WaveOut);
        mWaveOutDevice.Play();
        started = true;
    }
Exemple #14
0
 /// <summary>
 /// 关闭音频播放,释放资源。
 /// </summary>
 public static void AudioCleanUp()
 {
     if (AudioFileReader != null)
     {
         AudioFileReader?.Dispose();
         AudioFileReader = null;
     }
     if (WavePlayer != null)
     {
         WavePlayer?.Stop();
         WavePlayer?.Dispose();
         WavePlayer = null;
     }
 }
Exemple #15
0
        public void Init(int deviceNumber)
        {
            if (outputDevice != null)
            {
                outputDevice.Dispose();
            }

            var output = new WaveOutEvent();

            output.DeviceNumber = deviceNumber;
            output.Init(mixer);
            output.Play();

            outputDevice = output;
        }
Exemple #16
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog d = new OpenFileDialog();

            d.Filter = "MP3 file|*.mp3";
            d.Title  = "Choose file";
            if (d.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            Mp3FileReader reader = new Mp3FileReader(d.FileName);

            listView1.Items.Clear();
            listView1.Items.Add(new ListViewItem(
                                    new String[] { "Average bytes per second", reader.Mp3WaveFormat.AverageBytesPerSecond.ToString() }
                                    ));
            listView1.Items.Add(new ListViewItem(
                                    new String[] { "Bits per sample", reader.WaveFormat.BitsPerSample.ToString() }
                                    ));
            listView1.Items.Add(new ListViewItem(
                                    new String[] { "Channels", reader.WaveFormat.Channels.ToString() }
                                    ));
            listView1.Items.Add(new ListViewItem(
                                    new String[] { "Encoding", reader.Mp3WaveFormat.Encoding.ToString() }
                                    ));
            listView1.Items.Add(new ListViewItem(
                                    new String[] { "Sample rate", reader.WaveFormat.SampleRate.ToString() }
                                    ));


            this.reader?.Dispose();
            this.reader = null;

            speedControl?.Dispose();
            speedControl = null;

            wout?.Dispose();
            wout = null;

            this.reader        = reader;
            hScrollBar11.Value = 0;
            progressBar1.Value = 0;

            var useTempo = radioButton1.Checked;

            speedControl = new VarispeedSampleProvider(this.reader.ToSampleProvider(), 100, new SoundTouchProfile(useTempo, false));
        }
Exemple #17
0
        public void Stop()
        {
            if (_bTalking)
            {
                lock (_obj)
                {
                    if (_bTalking)
                    {
                        _bTalking = false;
                    }
                    TalkStopped?.Invoke(this, EventArgs.Empty);
                }
            }
            if (_audioSource != null)
            {
                _audioSource.Listening      = false;
                _audioSource.DataAvailable -= AudioSourceDataAvailable;
                _audioSource.DataAvailable -= _audioSource_DataAvailablePipe;
            }

            if (_waveOut != null)
            {
                _waveOut.Stop();
                _waveOut.Dispose();
            }
        }
Exemple #18
0
        protected override void Dispose(bool disposing)
        {
            if (Disposed)
            {
                return;
            }

            if (IsPlaying)
            {
                Stop();
            }

            if (disposing)
            {
                if (_player != null)
                {
                    _player.PlaybackStopped -= PlaybackStopped;
                    _player?.Dispose();
                    _player = null;
                }

                if (_reader != null)
                {
                    _reader?.Close();
                    _reader?.Dispose();
                    _reader = null;
                }
                // Free any other managed objects here.
            }

            // Free any unmanaged objects here.
            Disposed = true;
        }
Exemple #19
0
        // Utility methodes
        private void StopAndCloseStream()
        {
            if (_waveOutDevice != null)
            {
                _waveOutDevice.Stop();
            }

            if (_activeStream != null)
            {
                try
                {
                    _inputStream.Close();
                    _inputStream = null;
                }
                catch
                {
                    _inputStream = null;
                }
            }

            if (_waveOutDevice != null)
            {
                _waveOutDevice.Dispose();
                _waveOutDevice = null;
            }
        }
 //Voorkomt het voorkomen van audio-artifacts bij snel afspelen van dingen.
 public static void Cleanup()
 {
     outputDevice.Dispose();
     outputDevice = null;
     outputDevice = new WaveOutEvent();
     outputDevice.Init(mixingWaveProvider);
 }
Exemple #21
0
        /// <summary>
        /// 关闭歌曲流并释放资源
        /// </summary>
        private static void UnLoad()
        {
            timer.Stop();

            if (waveout != null)
            {
                waveout.Stop();
                waveout.Dispose();
            }
            if (FileReader != null)
            {
                FileReader.Dispose();
            }

            setVolumeDelegate = null;
            waveout           = null;
            FileReader        = null;
            lrc = null;

            TimeSpan t = TimeSpan.FromTicks(0);

            Center.Mainw.setDisplayTime(t, t);
            Config.setPlayTime(t, t);
            Center.Mainw.setPlayPauseButtonIcon(!PlayControl.isPause);
        }
Exemple #22
0
        void auxili_PlaybackStopped(object sender, EventArgs e)
        {
            IWavePlayer auxxx = (IWavePlayer)sender;

            //error("auxxx detenido");

            aguante--;


            try
            {
                diccionarioReLocoMixer[auxxx].RemoveInputStream(diccionarioLoco[auxxx]);
                diccionarioReLocoMixer[auxxx].Close();
                diccionarioLoco.Remove(auxxx);
                diccionarioReLocoMixer.Remove(auxxx);

                auxxx.Dispose();

                auxxx = null;
            }
            catch (Exception err)
            {
                if (error != null)
                {
                    error(err.Message);
                }
            }
        }
Exemple #23
0
        private void Play()
        {
            if (playlist.Count < 1)
            {
                return;
            }
            playing = true;

            player = new WaveOutEvent();
            player.PlaybackStopped += (sender, e) =>
            {
                player?.Dispose();
                mp3FileReader?.Dispose();
                if (playlist.Any())
                {
                    Play();
                }
                else
                {
                    OnPlaybackStopped(e);
                }
            };

            mp3FileReader = new Mp3FileReader(playlist.Dequeue());
            player.Init(mp3FileReader);
            player.Play();
        }
Exemple #24
0
 void tryStop()
 {
     try
     {
         if (null != output)
         {
             output.Dispose();
             output = null;
         }
     }
     catch { }
     try
     {
         if (null != meter)
         {
             meter = null;
         }
     }
     catch { }
     try
     {
         if (null != source)
         {
             source.Dispose();
             source = null;
         }
     }
     catch { }
 }
Exemple #25
0
 public override void Stop()
 {
     m_AudioThread.Abort();
     m_OutputDevice.Stop();
     m_OutputDevice.Dispose();
     m_OutputDevice = null;
 }
Exemple #26
0
 public void Dispose()
 {
     Stop();
     CloseFile();
     playbackDevice?.Dispose();
     playbackDevice = null;
 }
Exemple #27
0
        public void Stop()
        {
            if (playbackState == StreamingPlaybackState.Stopped)
            {
                return;
            }
            if (!fullyDownloaded)
            {
                webRequest.Abort();
            }

            playbackState = StreamingPlaybackState.Stopped;
            if (waveOut != null)
            {
                waveOut.Stop();
                waveOut.Dispose();
                waveOut = null;
                vuMeter.StreamVolume -= Meter_StreamVolume;
                vuMeter = null;
            }
            _timer.Change(Timeout.Infinite, Timeout.Infinite);
            LevelLeftValue  = 0;
            LevelRightValue = 0;
            // n.b. streaming thread may not yet have exited
            Thread.Sleep(500);
            bufferedSeconds = 0;
        }
        public static void Dispose()
        {
            if (mp3Channel != null)
            {
                mp3Channel.Dispose();
            }
            DisposeVST();

            if (UsedLibrary == AudioLibrary.NAudio)
            {
                //NAUDIO
                Samples.Clear();
                if (playbackDevice != null)
                {
                    playbackDevice.Stop();
                    playbackDevice.Dispose();
                    playbackDevice = null;
                }

                if (Mixer32 != null)
                {
                    Mixer32.Dispose(); Mixer32 = null;
                }
            }
            UsedLibrary = AudioLibrary.Null;
        }
Exemple #29
0
        private async void Load()
        {
            if (player != null)
            {
                player.Dispose();
                player = null;
            }
            reader = null; // will be disposed by player

            var picker = new FileOpenPicker();

            picker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
            picker.FileTypeFilter.Add("*");
            var file = await picker.PickSingleFileAsync();

            if (file == null)
            {
                return;
            }
            var stream = await file.OpenAsync(FileAccessMode.Read);

            if (stream == null)
            {
                return;
            }
            this.selectedStream   = stream;
            PlayCommand.IsEnabled = true;
        }
        /// <summary>
        /// Destroys the audio renderer.
        /// Makes it useless.
        /// </summary>
        private void Destroy()
        {
            lock (SyncLock)
            {
                if (AudioDevice != null)
                {
                    AudioDevice.Dispose();
                    AudioDevice = null;
                }

                if (AudioBuffer != null)
                {
                    AudioBuffer.Dispose();
                    AudioBuffer = null;
                }

                if (AudioProcessor == null)
                {
                    return;
                }

                AudioProcessor.Dispose();
                AudioProcessor = null;
            }
        }
        private void DisposeInternal(IWavePlayer player, WaveStream file)
        {
            new TaskFactory().StartNew(() => {
                if(player != null) {
                    player.Dispose();
                }

                if(file != null) {
                    // Given that the NAudio framework gives no access to inner systems the best way to
                    // assure the player has been disposed before disposing the file is to wait a while
                    Task.Delay(1000).Wait();
                    file.Dispose();
                }
            });
        }
Exemple #32
0
 // Stops and disposes of the wave player. Wave players created through
 // the CreateWavePlayer method should be released by this method.
 private void ReleaseWavePlayer(IWavePlayer player)
 {
     if (player != null)
     {
         player.Stop();
         player.Dispose();
     }
 }
Exemple #33
0
        public void Run(string[] args)
        {
            m_settingsModel = LoadSettings();
            m_running = true;
            m_eyeClients = new Dictionary<string, TcpClient>();
            m_controllerClients = new Dictionary<string, ControllerItem>();
            m_eyeDataQueue = new Queue<byte[]>();
            m_controllerDataQueue = new Queue<ControllerData>();
            m_commandsQueue = new Queue<Command>();
            m_waveOutDevice = new WaveOut();
            m_audioFileReader = new AudioFileReader("alarms/default.mp3");
            m_waveOutDevice.Init(m_audioFileReader);

            var argMode = ArgMode.None;
            foreach (var arg in args)
            {
                if (argMode == ArgMode.None)
                {
                    if (arg == "-ep" || arg == "--eye-port")
                        argMode = ArgMode.EyePort;
                    else if (arg == "-cp" || arg == "--controller-port")
                        argMode = ArgMode.ControllerPort;
                    else if (arg == "-t" || arg == "--token")
                        argMode = ArgMode.Token;
                    else if (arg == "-tr" || arg == "--treshold")
                        argMode = ArgMode.Treshold;
                    else if (arg == "-aa" || arg == "--armed-alarm")
                        argMode = ArgMode.ArmedAlarm;
                    else if (arg == "-s" || arg == "--silent")
                        argMode = ArgMode.Silent;
                }
                else if (argMode == ArgMode.EyePort)
                {
                    var v = m_settingsModel.EyePort;
                    if (int.TryParse(arg, out v))
                        m_settingsModel.EyePort = v;
                    argMode = ArgMode.None;
                }
                else if (argMode == ArgMode.ControllerPort)
                {
                    var v = m_settingsModel.ControllerPort;
                    if (int.TryParse(arg, out v))
                        m_settingsModel.ControllerPort = v;
                    argMode = ArgMode.None;
                }
                else if (argMode == ArgMode.Token)
                {
                    m_settingsModel.Token = arg.Trim();
                    argMode = ArgMode.None;
                }
                else if (argMode == ArgMode.Treshold)
                {
                    var v = m_settingsModel.Treshold;
                    if (int.TryParse(arg, out v))
                        m_settingsModel.Treshold = v;
                    argMode = ArgMode.None;
                }
                else if (argMode == ArgMode.ArmedAlarm)
                {
                    if (arg == "y" || arg == "yes" || arg == "t" || arg == "true")
                        m_settingsModel.ArmedAlarm = true;
                    else if (arg == "n" || arg == "no" || arg == "f" || arg == "false")
                        m_settingsModel.ArmedAlarm = false;
                    argMode = ArgMode.None;
                }
                else if (argMode == ArgMode.Silent)
                {
                    if (arg == "y" || arg == "yes" || arg == "t" || arg == "true")
                        m_settingsModel.Silent = true;
                    else if (arg == "n" || arg == "no" || arg == "f" || arg == "false")
                        m_settingsModel.Silent = false;
                    argMode = ArgMode.None;
                }
            }

            m_alarmIsArmed = m_settingsModel.ArmedAlarm;
            Console.WriteLine("* Connection token: " + m_settingsModel.Token);

            SpawnEyeListenerTask();
            SpawnControllerListenerTask();
            SpawnEyeProcessorTask();
            SpawnControllerProcessorTask();
            SpawnCommandsExecutorTask();

            while (m_running)
            {
                var line = Console.ReadLine();
                if (line == "exit")
                    m_running = false;
                else if (line == "arm")
                    ArmAlarm();
                else if (line == "disarm")
                    DisarmAlarm();
                else if (line == "alarm-on")
                    StartAlarm();
                else if (line == "alarm-off")
                    StopAlarm();
            }

            lock (m_commandsLock)
            {
                if (m_commandsQueue != null)
                {
                    foreach (var command in m_commandsQueue)
                        command.PerformAction();
                    m_commandsQueue.Clear();
                }
            }
            lock (m_eyeClientsLock)
            {
                if (m_eyeClients != null)
                    foreach (var eye in m_eyeClients)
                        eye.Value.Close();
            }
            lock (m_controllerClientsLock)
            {
                if (m_controllerClients != null)
                    foreach (var controller in m_controllerClients)
                        controller.Value.Client.Close();
            }
            while (true)
            {
                lock (m_lock)
                {
                    if (m_eyeListener == null && m_controllerListener == null && m_eyeDataQueue == null && m_controllerDataQueue == null && m_commandsQueue == null)
                        break;
                }
                Thread.Sleep(10);
            }
            m_alarmIsPlaying = false;
            lock (m_alarmLock)
            {
                m_waveOutDevice.Stop();
                m_audioFileReader.Dispose();
                m_audioFileReader = null;
                m_waveOutDevice.Dispose();
                m_waveOutDevice = null;
            }
            m_eyeClients = null;
            m_controllerClients = null;
            SaveSettings(m_settingsModel);
            Thread.Sleep(1000);
        }