Esempio n. 1
0
        public async Task TogglePlayPause()
        {
            if (IsLoading || _soundSource == null || _soundOut == null)
            {
                return;
            }

            if (_fadingService.IsFading)
            {
                _fadingService.Cancel();
            }

            if (_soundOut.PlaybackState == PlaybackState.Playing)
            {
                _playTimeStopwatch.Stop();
                _isPausing = true;
                CurrentStateChanged();
                await _fadingService.FadeOut(_soundOut, Volume);

                _soundOut?.Pause();
                _isPausing = false;
                CurrentStateChanged();
            }
            else
            {
                _playTimeStopwatch.Start();
                _soundOut?.Play();
                CurrentStateChanged();
                await _fadingService.FadeIn(_soundOut, Volume);
            }
        }
Esempio n. 2
0
        public void PlayBgm(string song, bool resolvedName = false)
        {
            CleanupPlayback();

            var filename = resolvedName
                ? song
                : $"{AppContext.BaseDirectory}/assets/bgm/{song}.ogg";

            _musicSource =
                CodecFactory.Instance.GetCodec(filename)
                .ChangeSampleRate(11025)
                .ToSampleSource()
                .ToMono()
                .ToWaveSource();
            _musicOut = new WasapiOut {
                Latency = 100
            };
            _musicOut.Initialize(_musicSource);

            if (PlaybackStopped != null)
            {
                _musicOut.Stopped += PlaybackStopped;
            }

            _musicOut?.Play();
        }
Esempio n. 3
0
 public void TooglePlayPause()
 {
     if (_soundOut?.PlaybackState == PlaybackState.Playing)
     {
         _soundOut?.Pause();
     }
     else
     {
         _soundOut?.Play();
     }
     CurrentStateChanged();
 }
Esempio n. 4
0
        private void CanHandleEOFOnReplayTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);

            soundOut.Initialize(source);
            soundOut.Stopped += (s, e) => waitHandle.Set();

            for (int i = 0; i < BasicIterationCount; i++)
            {
                soundOut.Play();
                waitHandle.WaitOne();
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);
                source.Position = 0;
            }
        }
Esempio n. 5
0
        public override void Run(CommandContext context)
        {
            var sfxMatch = sfxPaths.Where(x => Path.GetFileNameWithoutExtension(x) == context.CommandText).FirstOrDefault();

            if (sfxMatch != null)
            {
                WaveSource = CodecFactory.Instance.GetCodec(sfxMatch)
                             .ToSampleSource()
                             .ToMono()
                             .ToWaveSource();
                SoundOut = new WasapiOut();
                SoundOut.Initialize(WaveSource);
                SoundOut.Volume = Volume;
                SoundOut.Play();
            }
        }
Esempio n. 6
0
        public OrderSound(string message, float Depth, float Frequency, float Feedback, float WetDryMix, float ReverbTime, float HighFrequencyRTRatio)
        {
            Thread theRT = new Thread(delegate()
            {
                {
                    m_AudioStream = new MemoryStream();
                    using (SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer())
                    {
                        speechSynthesizer.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Child);
                        speechSynthesizer.Rate = Rate;
                        speechSynthesizer.SetOutputToWaveStream(m_AudioStream);
                        speechSynthesizer.SpeakCompleted += new EventHandler <SpeakCompletedEventArgs>(WriteCompleate);
                        speechSynthesizer.SpeakAsync(message);
                        state = SOUNDSTATE.FORMING;
                        manualReset.WaitOne();
                        state = SOUNDSTATE.READY;
                        m_AudioStream.Seek(0, SeekOrigin.Begin);
                        flanger = new FlangerEffect(GetSoundSource(m_AudioStream))
                        {
                            Depth     = Depth,
                            Frequency = Frequency,
                            Feedback  = Feedback,
                            WetDryMix = WetDryMix
                        };
                        rev = new DmoWavesReverbEffect(flanger.ToStereo())
                        {
                            ReverbTime           = ReverbTime,
                            HighFrequencyRTRatio = HighFrequencyRTRatio
                        };
                        rev.WriteToWaveStream(m_AudioStream2);
                        soundOut = GetSoundOut();
                        soundOut.Initialize(GetSoundSource(m_AudioStream2));
                        soundOut.Volume   = 1;
                        soundOut.Stopped += DonePlaying;
                        soundOut.Play();

                        state = SOUNDSTATE.PLAYING;
                        manualReset.WaitOne();
                    }
                }
            })
            {
                IsBackground = true
            };

            theRT.Start();
        }
Esempio n. 7
0
        //Playing function
        public void playing()
        {
            if (db > 0)
            {
                //Init
                device.Stop();
                int index = (int)playlist.list.CurrentRow.Cells[0].Value - 1;
                path = tracks[index];

                if (paused == 0)
                {
                    audio = CodecFactory.Instance.GetCodec(path);
                }
                device.Initialize(audio);
                device.Volume = (float)track_volume.Value / 10;
                device.Play();
                paused = 0;

                //Getting audio information
                label_name.Text      = Path.GetFileNameWithoutExtension(path);
                label_extension.Text = Path.GetExtension(path);
                label_progress.Text  = "00:00";
                label_length.Text    = "";
                length = (int)audio.GetLength().TotalSeconds;

                if (length / 60 < 10)
                {
                    label_length.Text += "0" + length / 60 + ":";
                }
                else
                {
                    label_length.Text += length / 60 + ":";
                }

                if (length % 60 < 10)
                {
                    label_length.Text += "0" + length % 60;
                }
                else
                {
                    label_length.Text += length % 60;
                }

                timer.Start();
            }
        }
        public void play()
        {
            ISampleSource source = CodecFactory.Instance.GetCodec(this.sfxPath).ToSampleSource();

            var notificationSource = new SingleBlockNotificationStream(source);



            _source = notificationSource.ToWaveSource(16);



            //play the audio
            _soundOut = new WasapiOut();
            _soundOut.Initialize(_source);
            _soundOut.Play();
        }
Esempio n. 9
0
        public async void TogglePlayPause()
        {
            try
            {
                if (IsLoading)
                {
                    _playAfterLoading = !_playAfterLoading;
                    return;
                }

                if (CurrentTrack == null)
                {
                    return;
                }
                if (_fader != null && _fader.IsFading)
                {
                    _fader.CancelFading();
                    _fader.WaitForCancel();
                }
                if (_soundOut.PlaybackState == PlaybackState.Playing)
                {
                    if (_crossfade != null && _crossfade.IsCrossfading)
                    {
                        _crossfade.CancelFading();
                    }
                    _isfadingout = true;
                    CurrentStateChanged();
                    await _fader.FadeOut(_soundOut, Volume);

                    _soundOut.Pause();
                    CurrentStateChanged();
                    _isfadingout = false;
                }
                else
                {
                    _soundOut.Play();
                    CurrentStateChanged();
                    await _fader.FadeIn(_soundOut, Volume);
                }
            }
            catch (ObjectDisposedException)
            {
                //Nearly everywhere in this code block can an ObjectDisposedException get thrown. We can safely ignore that
            }
        }
Esempio n. 10
0
        private async void Open_Click(object sender, RoutedEventArgs e)
        {
            var ofn = new OpenFileDialog {
                Filter = CodecFactory.SupportedFilesFilterEn
            };

            if (ofn.ShowDialog() == true)
            {
                _soundOut.Stop();
                if (_notificationSource != null)
                {
                    _notificationSource.Dispose();
                }

                var source = CodecFactory.Instance.GetCodec(ofn.FileName);
                //if (source.Length < 0x320000) //< 50MB
                if (source is MediaFoundationDecoder)
                {
                    if (source.Length < 10485760) //10MB
                    {
                        source = new CachedSoundSource(source);
                    }
                    else
                    {
                        Stopwatch stopwatch = Stopwatch.StartNew();
                        source = new FileCachedSoundSource(source);
                        stopwatch.Stop();
                        Debug.WriteLine(stopwatch.Elapsed.ToString());
                    }
                }
                source.Position = 0;
                await LoadWaveformsAsync(source);

                source.Position = 0;

                _sampleSource       = source.ToSampleSource();
                _notificationSource = new NotificationSource(_sampleSource)
                {
                    Interval = 100
                };
                _notificationSource.BlockRead += (o, args) => { UpdatePosition(); };
                _soundOut.Initialize(_notificationSource.ToWaveSource());
                _soundOut.Play();
            }
        }
Esempio n. 11
0
 private void PlayNext()
 {
     CurrentSong = GetNext();
     WaveSource  = CodecFactory.Instance.GetCodec(CurrentSong.FilePath)
                   .ToSampleSource()
                   .ToMono()
                   .ToWaveSource();
     SoundOut = new WasapiOut();
     SoundOut.Initialize(WaveSource);
     SoundOut.Stopped += (sender, e) => { PlayNext(); };
     SoundOut.Volume   = Volume;
     SoundOut.Play();
     ConsoleHelper.WriteLine($"Now Playing: \"{CurrentSong.Title}\" by {CurrentSong.Artist}");
     OnSongChanged(this, new SongChangeEventArgs(CurrentSong));
     if (RequestedSongs.Count > 0)
     {
         DownloadNextInQueueAsync().GetAwaiter().GetResult();
     }
 }
Esempio n. 12
0
        public void Reverb()
        {
            var soundIn = new WasapiCapture(true, AudioClientShareMode.Shared, 10);

            soundIn.Initialize();
            IWaveSource source = new SoundInSource(soundIn)
            {
                FillWithZeros = true
            };

            PreLowpassCutoff = 110;
            InGain           = 10;
            var eSource = new DmoWavesReverbEffect(source);

            soundIn.Start();
            _soundOut = new WasapiOut();
            _soundOut.Initialize(eSource);
            _soundOut.Play();
        }
Esempio n. 13
0
 public Exception Play(string uri)
 {
     Stop();
     try
     {
         soundSource = GetSoundSource(uri);
         soundOut.Initialize(soundSource);
         soundOut.Play();
         return(null);
     }
     catch (Exception e)
     {
         if (soundSource != null)
         {
             soundSource.Dispose();
             soundSource = null;
         }
         return(e);
     }
 }
Esempio n. 14
0
        private void OpenSource(IWaveSource source)
        {
            try
            {
                Stop(); //if playing -> stop playback
                _audioSource = source;

                _gainSource = new GainSource(source)
                {
                    Gain = (float)this.Gain
                };

                source = SetupVisualization(_gainSource.ToWaveSource(16));

                if (WasapiOut.IsSupportedOnCurrentPlatform) // > Vista
                {
                    _soundOut = new WasapiOut(false, CSCore.CoreAudioAPI.AudioClientShareMode.Shared, 100);
                }
                else // < Vista
                {
                    _soundOut = new DirectSoundOut()
                    {
                        Latency = 100
                    };
                }

                _soundOut.Initialize(source);
                _soundOut.Stopped += OnPlaybackStopped;
                _soundOut.Play();
            }
            catch (CSCore.CoreAudioAPI.CoreAudioAPIException ex)
            {
                MessageBox.Show("Unknown CoreAudioAPI-error: 0x" + ex.ErrorCode.ToString("x"), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Stop();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unknown error: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Stop();
            }
        }
Esempio n. 15
0
 public void ReproducirCD(char disp)
 {
     Disquetera = CDDrive.Open(disp);
     if (Disquetera == null)
     {
         Log.Instance.PrintMessage("Cannot read the CD Drive, the device is not ready.", MessageType.Error);
         throw new IOException();
     }
     FormatoSonido = FormatoSonido.CDA;
     PistaCD[] Pistas = LeerCD(disp);
     if (Pistas == null)
     {
         return;
     }
     PistasCD = Pistas;
     _output  = new WasapiOut(false, AudioClientShareMode.Shared, 100);
     _sound   = Disquetera.ReadTrack(Pistas[0]);
     _output.Initialize(_sound);
     _output.Play();
     Log.Instance.PrintMessage("CD has loaded correctly", MessageType.Correct);
 }
Esempio n. 16
0
        public IObservable <Unit> PlayASound(string filename)
        {
            return(Observable.Create <Unit>(observer =>
            {
                //Contains the sound to play
                IWaveSource soundSource = GetSoundSource(filename);
                LoopStream ls = new LoopStream(soundSource);
                //SoundOut implementation which plays the sound
                ISoundOut soundOut = GetSoundOut();
                //Tell the SoundOut which sound it has to play
                soundOut.Initialize(ls);
                //Play the sound
                soundOut.Play();

                return Disposable.Create(() =>
                {
                    //Stop the playback
                    soundOut.Stop();
                    soundOut.Dispose();
                    soundSource.Dispose();
                });
            }));
        }
Esempio n. 17
0
        // 0.1초당 한번씩 실행되는 함수
        private async void Update()
        {
            while (_isUpdating)
            {
                _progressBar = (float)_soundSource.Position / _soundSource.Length * (float)Screen.Width;

                ProgressBar.Width = _progressBar;

                if (_soundSource.Position == _soundSource.Length)
                {
                    if (++playingIndex >= playingMusicList.Count)
                    {
                        playingIndex = 0;
                    }

                    Open(playingMusicList[playingIndex].Path);
                    _soundOut.Play();
                }

                await Task.Delay(100);
            }
        }
Esempio n. 18
0
        public async void TogglePlayPause()
        {
            if (IsLoading)
            {
                _playAfterLoading = !_playAfterLoading;
                return;
            }

            if (CurrentTrack == null)
            {
                return;
            }
            if (_fader != null && _fader.IsFading)
            {
                _fader.CancelFading(); _fader.WaitForCancel();
            }
            if (_soundOut.PlaybackState == PlaybackState.Playing)
            {
                if (_crossfade != null && _crossfade.IsCrossfading)
                {
                    _crossfade.CancelFading();
                }
                _isfadingout = true;
                await _fader.FadeOut(_soundOut, this.Volume);

                _soundOut.Pause();
                CurrentStateChanged();
                _isfadingout = false;
            }
            else
            {
                _soundOut.Play();
                CurrentStateChanged();
                await _fader.FadeIn(_soundOut, this.Volume);
            }
        }
Esempio n. 19
0
        private void btnPlay_Click(object sender, EventArgs e)
        {
            IAudioFilter waveRdr;

            // For the purposes of testing we process .raw files as
            // containing 16-bit stereo PCM data at 44.1KHz.  This is much
            // like a .wav file but without the header.
            if (lblFileName.Text.EndsWith(".raw"))
            {
                waveRdr = new RawFileReader(lblFileName.Text, 16, 44100, 2);
            }
            else
            {
                IWaveSource inputFile = CodecFactory.Instance.GetCodec(lblFileName.Text);

                waveRdr = new WaveSourceReader(inputFile);
            }

            // Convert to 24 bit samples (if needed)
            ConvertBitsPerSample bpsConvert = new ConvertBitsPerSample(waveRdr, 24);

            // Create a crossover and catch any errors in case the frequency parameters
            // are not valid
            Crossover crossover;

            try
            {
                crossover = Crossover.createThreeWayCrossover(Int32.Parse(txtLowerFreq.Text),
                                                              Int32.Parse(txtUpperFreq.Text), Int32.Parse(txtLowerTrans.Text), Int32.Parse(txtUpperTrans.Text),
                                                              waveRdr.SampleRate, true, false, 10.0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Error building crossover: " + ex.Message);
                return;
            }

            // Start creating filters...
            CrossoverThreeWayFilter filter = new CrossoverThreeWayFilter(bpsConvert, crossover);

            sampleTap = new SampleTap(filter, SAMPLE_LEN);



            int crossoverIdx = 1;

            if (rdoPlayWoofer.Checked)
            {
                crossoverIdx = 0;
            }
            else if (rdoPlayMidrange.Checked)
            {
                crossoverIdx = 1;
            }
            else if (rdoPlayTweeter.Checked)
            {
                crossoverIdx = 2;
            }

            channelSelectFilter = new SelectCrossover(sampleTap, crossoverIdx);

            volumeControlFilter = new VolumeControl(channelSelectFilter);

            // Only needed for playback through Windows
            lastFilterStep = new ConvertBitsPerSample(volumeControlFilter, 16);

            // Done creating filters...



            tbarFilePosition.Value = 0;
            // Max in seconds
            tbarFilePosition.Maximum = (int)(lastFilterStep.Length / lastFilterStep.SampleRate / lastFilterStep.NumberOfChannels);
            tbarFilePosition.Enabled = true;


            // Playback through Windows
            IWaveSource finalWaveSource = new FilterToWaveSource(lastFilterStep);

            //_soundOut = new WasapiOut();
            soundOutDevice = new WaveOut();
            soundOutDevice.Initialize(finalWaveSource);
            soundOutDevice.Play();

            tmrUpdateViz.Start();
        }
Esempio n. 20
0
        //***********************************************************************************************************************************************************************************************************

        #region Control recorder (start, stop, pause, resume)

        /// <summary>
        /// Start a new record
        /// </summary>
        public void StartRecord()
        {
            try
            {
                if (RecordState == RecordStates.RECORDING)
                {
                    return;
                }

                if (TrackInfo == null)
                {
                    _logHandle.Report(new LogEventWarning("Record not started, because no track info exists."));
                    return;
                }
                CreateFilePath();
                if (RecorderRecSettings.FileExistMode == RecorderFileExistModes.SKIP && (System.IO.File.Exists(FileStrWAV) || System.IO.File.Exists(FileStrMP3)))
                {
                    _logHandle.Report(new LogEventWarning("Record (\"" + TrackInfo?.TrackName + "\") not started, because FileExistMode == SKIP and file already exists."));
                    return;
                }

                if (!Directory.Exists(RecorderRecSettings.BasePath))
                {
                    _logHandle.Report(new LogEventWarning("Record (\"" + TrackInfo?.TrackName + "\") not started, because RecordPath is invalid."));
                    return;
                }

                if (WasapiOut.IsSupportedOnCurrentPlatform)
                {
                    _silenceOut = new WasapiOut();
                }
                else
                {
                    _silenceOut = new DirectSoundOut();
                }
                _silenceOut.Initialize(new SilenceGenerator());
                _silenceOut.Play();         //Play silence because otherwise silent parts aren't recorded

                _capture = new WasapiLoopbackCapture();

                MMDeviceEnumerator devEnumerator = new MMDeviceEnumerator();
                MMDeviceCollection mMDevices     = devEnumerator.EnumAudioEndpoints(DataFlow.All, DeviceState.All);

                MMDevice dev;
                if (RecorderRecSettings.RecorderDeviceName.ToLower().Contains("default"))
                {
                    dev = devEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
                }
                else
                {
                    dev = mMDevices.Where(d => d.DeviceState == DeviceState.Active && d.FriendlyName == RecorderRecSettings.RecorderDeviceName)?.First();
                }

                if (dev == null)
                {
                    _logHandle.Report(new LogEventError("Record (\"" + TrackInfo?.TrackName + "\") not started, because device \"" + RecorderRecSettings.RecorderDeviceName + "\" wasn't found." + (RecorderRecSettings.RecorderDeviceName.Contains("CABLE Input") ? " Make sure that \"VB Cable\" is installed correctly." : "")));
                    return;
                }

                _capture.Device = dev;
                _capture.Initialize();      // Important!!! First set the capture device, then call Initialize(); otherwise audio is captured from the previous device

                SoundInSource soundInSource    = new SoundInSource(_capture);
                SampleToPcm16 soundInSourcePCM = new SampleToPcm16(soundInSource.ToSampleSource());     //Used to convert _capture to Pcm16 format

                Directory.CreateDirectory(Path.GetDirectoryName(FileStrWAV));
                _wavWriterFormat        = new WaveFormat(_capture.WaveFormat.SampleRate, soundInSourcePCM.WaveFormat.BitsPerSample, _capture.WaveFormat.Channels, AudioEncoding.Pcm, _capture.WaveFormat.ExtraSize); //WAV file must be 16-bit PCM file for normalizing with normalize.exe
                _wavWriter              = new WaveWriter(FileStrWAV, _wavWriterFormat);
                _wavWriterPositionBytes = 0;

                soundInSource.DataAvailable += (s, capData) =>
                {
                    if (RecordState == RecordStates.RECORDING)              //Only record when RecordState is RECORDING
                    {
                        byte[] buffer = new byte[soundInSourcePCM.WaveFormat.BytesPerSecond / 2];
                        int    read;

                        while ((read = soundInSourcePCM.Read(buffer, 0, buffer.Length)) > 0) //keep reading as long as we still get some data
                        {
                            _wavWriter.Write(buffer, 0, read);                               //write the read data to a file
                            _wavWriterPositionBytes += read;
                        }
                    }
                };

                _capture.Start();

                RecordState = RecordStates.RECORDING;
                _logHandle.Report(new LogEventInfo("Record (\"" + TrackInfo?.TrackName + "\") started."));
                WasRecordPaused = false;
            }
            catch (Exception ex)
            {
                _logHandle.Report(new LogEventError("Error while starting record: " + ex.Message));
            }
        }
Esempio n. 21
0
 private void VolumeResetTestInternal(ISoundOut soundOut, IWaveSource source)
 {
     soundOut.Initialize(source);
     soundOut.Play();
     soundOut.Volume = 0.5f;
     Assert.AreEqual(0.5f, Math.Round(soundOut.Volume, 3)); //round => directsound may causes problems because of db => lin calculations.
     Thread.Sleep(50);
     soundOut.Stop();
     soundOut.Initialize(source);
     soundOut.Play();
     Assert.AreEqual(1.0f, soundOut.Volume);
     soundOut.Stop();
 }
Esempio n. 22
0
        public void Play()
        {
            while (!emptyPlaylist)
            {
                while (CurrPlaying < CurrPlaylist.SongList.Count)
                {
                    CurrSong = Shuffle ? CurrPlaylist.SongList[shuffleArr[CurrPlaying]] : CurrPlaylist.SongList[CurrPlaying];



                    using (soundSource = CodecFactory.Instance.GetCodec(CurrSong.SongPath)
                                         .ChangeSampleRate(32000)
                                         .AppendSource(Equalizer.Create10BandEqualizer, out equalizer).ToWaveSource())
                    {
                        using (soundOut = GetSoundOut())
                        {
                            soundOut.Initialize(soundSource);
                            soundOut.Play();
                            OnSongChangedHandler?.Invoke(this, new OnSongChanged(CurrSong.SongName));



                            if (paused)
                            {
                                paused = false;
                                soundOut.Pause();
                            }



                            while (soundOut.PlaybackState == PlaybackState.Playing || soundOut.PlaybackState == PlaybackState.Paused)
                            {
                                if (songChange)
                                {
                                    songChange = false;
                                    break;
                                }
                                if (plChanged)
                                {
                                    plChanged = false;

                                    break;
                                }
                                if (initialized)
                                {
                                    Time            = (int)(soundSource.Position / soundSource.WaveFormat.BytesPerSecond);
                                    Progress        = (double)soundSource.Position / soundSource.Length;
                                    soundOut.Volume = Volume;
                                }



                                Thread.Sleep(1);
                            }
                        }
                    }
                    if (!RepeatSong)
                    {
                        CurrPlaying++;
                    }
                    Progress = 0;
                }
                #region repeat
                CurrPlaying = 0;
                switch (repeat)
                {
                case RepeatOptions.NoRepeat:
                    paused = true;
                    break;

                case RepeatOptions.GoToNextPlaylist:
                    CurrPlaylistNum++;
                    if (CurrPlaylistNum > ListOfPlaylists.Count)
                    {
                        CurrPlaylistNum = 0;
                    }
                    CurrPlaylist = ListOfPlaylists[CurrPlaylistNum];
                    break;
                }

                #endregion
            }
        }
Esempio n. 23
0
        private void CanReinitializeSoundOutTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            for (int i = 0; i < BasicIterationCount; i++)
            {
                Debug.WriteLine(soundOut.ToString());

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(100);

                soundOut.Stop();
                source.Position = 0;
            }
        }
Esempio n. 24
0
        private void PlayPauseResumeBehaviourTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            for (int i = 0; i < BasicIterationCount; i++)
            {
                soundOut.Initialize(source);
                //--

                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                Thread.Sleep(50);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Resume();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);
                //--
                Thread.Sleep(250);
                //--
                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                Thread.Sleep(50);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);
                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Resume();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);
                //--

                soundOut.Stop();
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                Thread.Sleep(10);

                soundOut.Stop();
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                Thread.Sleep(50);

                //--
                soundOut.Stop();
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);
                source.Position = 0;
            }
        }
Esempio n. 25
0
        private void PlaySoundFile(object filename)
        {
            using (IWaveSource soundSource = CodecFactory.Instance.GetCodec(filename as string))
            {
                //SoundOut implementation which plays the sound
                using (soundOut = GetSoundOut())
                {
                    //Tell the SoundOut which sound it has to play
                    soundOut.Initialize(soundSource);

                    //Play the sound
                    soundOut.Play();

                    while (soundOut.PlaybackState == PlaybackState.Playing)
                    {
                        Thread.Sleep(500);
                    }

                    //Stop the playback
                    if(soundOut.PlaybackState != PlaybackState.Stopped) soundOut.Stop();
                    OnPlaybackStop(this, null);
                }
            }
        }
Esempio n. 26
0
        public static void playMusic(string[] args)
        {
            try
            {
                if (!rpcInitialised)
                {
                    client.Initialize();
                    rpcInitialised = true;
                }
                Console.Clear();
                var i = 5;
                //initialize file and play
                waveSource = CodecFactory.Instance.GetCodec(MusicData.queue[0]).ToSampleSource().ToWaveSource();
                soundOut   = new WasapiOut()
                {
                    Latency = 100
                };
                soundOut.Initialize(waveSource);
                soundOut.Play();
                soundOut.Volume = MusicData.volume;

                //get the tags
                TagLib.File file   = TagLib.File.Create(MusicData.queue[0]);
                TimeSpan    time   = waveSource.GetTime(waveSource.Length);
                var         title  = String.IsNullOrWhiteSpace(file.Tag.Title) ? file.Name.Split("\\")[file.Name.Split("\\").Length - 1].Split(".")[0] : file.Tag.Title;
                var         artist = file.Tag.Performers.Length == 0 ? "N/A" : file.Tag.Performers.Length > 1 ? String.Join(", ", file.Tag.Performers) : file.Tag.Performers[0];
                var         album  = String.IsNullOrWhiteSpace(file.Tag.Album) ? "N/A" : file.Tag.Album;
                Console.WriteLine("Title: " + title);
                Console.WriteLine("Artist: " + artist);
                Console.WriteLine("Album: " + album);
                RewriteLine(5, "Type \"help\" for a commands list");

                //commands while playing
                while (soundOut.PlaybackState == PlaybackState.Playing || soundOut.PlaybackState == PlaybackState.Paused)
                {
                    Console.SetCursorPosition(0, i);
                    i += 2;
                    while (true)
                    {
                        //get the time
                        double   ms = waveSource.Position * 1000.0 / waveSource.WaveFormat.BitsPerSample / waveSource.WaveFormat.Channels * 8 / waveSource.WaveFormat.SampleRate;
                        TimeSpan ts = TimeSpan.FromMilliseconds(ms);
                        setPresence(title, artist, (time.TotalMilliseconds - ms), "logo", album, soundOut.PlaybackState == PlaybackState.Playing ? "playing" : "paused");
                        if (Console.KeyAvailable)
                        {
                            var input = Console.ReadLine();
                            switch (input)
                            {
                            case "help":
                                Console.WriteLine("Commands:");
                                Console.WriteLine("\"help\": Shows this menu");
                                Console.WriteLine("\"resume\": Resumes curent song");
                                Console.WriteLine("\"pause\": Pauses current song");
                                Console.WriteLine("\"skip\": Skips current song");
                                Console.WriteLine("\"volume\": View current volume or set the volume to a number from 0-100");
                                Console.WriteLine("\"clear\": Clears the console");
                                Console.WriteLine("\"stop\": Stops the application");
                                i += 6;
                                break;

                            case "resume":
                                if (soundOut.PlaybackState != PlaybackState.Playing)
                                {
                                    soundOut.Play();
                                    Console.WriteLine("Unpaused \"{0}\"", file.Tag.Title);
                                }
                                else
                                {
                                    Console.WriteLine("The song is already playing");
                                }
                                break;

                            case "pause":
                                if (soundOut.PlaybackState != PlaybackState.Paused)
                                {
                                    soundOut.Pause();
                                    Console.WriteLine("Paused \"{0}\"", file.Tag.Title);
                                }
                                else
                                {
                                    Console.WriteLine("The song is already paused");
                                }
                                break;

                            case "skip":
                                soundOut.Stop();
                                CleanupPlayback();
                                MusicData.queue.RemoveAt(0);
                                if (MusicData.queue.Count() >= 1)
                                {
                                    playMusic(args);
                                    return;
                                }
                                else
                                {
                                    mainProgram(args);
                                }
                                break;

                            case "clear":
                                Console.Clear();
                                RewriteLine(1, "Title: " + file.Tag.Title);
                                RewriteLine(2, "Artist: " + artist);
                                RewriteLine(3, "Album: " + file.Tag.Album);
                                RewriteLine(4, ts.ToString(@"hh\:mm\:ss") + " \\ " + time);
                                RewriteLine(5, "Type \"help\" for a commands list");
                                i = 5;
                                Console.SetCursorPosition(0, i);
                                break;

                            case "stop":
                                MusicData.queue.RemoveRange(0, MusicData.queue.Count);
                                soundOut.Stop();
                                CleanupPlayback();
                                Main(args);
                                break;

                            case "volume":
                                bool did = false;
                                Console.WriteLine("The current volume is at {0}%", Math.Round(soundOut.Volume * 100));
                                Console.WriteLine("Do you want to change the volume? (y/n)");
                                while (!did)
                                {
                                    var response = Console.ReadLine().ToLower();
                                    if (response == "y")
                                    {
                                        float number;
                                        Console.WriteLine("What volume would you like to change it to?");
                                        var  value   = Console.ReadLine();
                                        bool success = float.TryParse(value, out number);
                                        if (success)
                                        {
                                            if (number > 100f || number < 0f)
                                            {
                                                Console.WriteLine("Volume must be between 0 and 100");
                                                break;
                                            }
                                            number          /= 100;
                                            soundOut.Volume  = number;
                                            MusicData.volume = number;
                                            Console.WriteLine("Volume changed to {0}%", Math.Round(soundOut.Volume * 100));
                                        }
                                        else
                                        {
                                            Console.WriteLine("\"{0}\" is not a valid number between 0 and 100", value);
                                        }
                                        did = true;
                                        break;
                                    }
                                    else if (response == "n")
                                    {
                                        did = true;
                                        break;
                                    }
                                    Console.WriteLine("Choose yes (y) or no (n)");
                                }
                                break;

                            default:
                                Console.WriteLine("Type \"help\" for a commands list");
                                break;
                            }
                        }
                        RewriteLine(4, ts.ToString(@"hh\:mm\:ss") + " \\ " + time.ToString(@"hh\:mm\:ss"));
                        if (soundOut.PlaybackState == PlaybackState.Stopped)
                        {
                            MusicData.queue.RemoveAt(0);
                            if (MusicData.queue.Count() >= 1)
                            {
                                CleanupPlayback();
                                playMusic(args);
                                return;
                            }
                            else
                            {
                                mainProgram(args);
                            }
                        }
                        Thread.Sleep(1000);
                    }
                }
            }
            catch
            {
                Console.WriteLine("An error occured, the file that this error occured on is {0} or {1}", MusicData.queue[0], MusicData.queue.Count >= 2 ? MusicData.queue[1] : "N/A");
            }
        }
Esempio n. 27
0
 public void Play()
 {
     _soundOut.Play();
 }
Esempio n. 28
0
        private void CanHandleEOFTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            int sourceLength = (int)source.GetLength().TotalMilliseconds;
            for (int i = 0; i < basic_iteration_count; i++)
            {
                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Pause();
                soundOut.Resume();

                Thread.Sleep(10);

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                source.Position = 0;
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
            }
        }
 private void StartSpeech(ISoundOut soundout, int priority)
 {
     bool started = false;
     while (!started)
     {
         if (activeSpeech == null)
         {
             lock (activeSpeechLock)
             {
                 Logging.Debug("Checking to see if we can start speech");
                 if (activeSpeech == null)
                 {
                     Logging.Debug("We can - setting active speech");
                     activeSpeech = soundout;
                     activeSpeechPriority = priority;
                     started = true;
                     Logging.Debug("Playing sound buffer");
                     soundout.Play();
                 }
             }
         }
         Thread.Sleep(10);
     }
 }
Esempio n. 30
0
        /// <summary>
        /// Play a blank sound. It keeps recording even when no sound is played.
        /// Loopback callback is triggered only when a sound is played.
        /// Playing a blank sound keep the recorder running even when there's no sound playing
        /// </summary>
        private void CaptureSilence()
        {
            _soundSilenceSource = new SilenceGenerator();

            _soundSilenceOut = GetSoundOut();

            _soundSilenceOut.Initialize(_soundSilenceSource);
            _soundSilenceOut.Play();
        }
Esempio n. 31
0
 private void PlayHandler()
 {
     _soundOut.Play();
     _updateTimer.IsEnabled = true;
     PositionValue          = 0;
 }
Esempio n. 32
0
        private void CanHandleEOFOnReplayTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
            soundOut.Initialize(source);
            soundOut.Stopped += (s, e) => waitHandle.Set();

            for (int i = 0; i < BasicIterationCount; i++)
            {
                soundOut.Play();
                waitHandle.WaitOne();
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);
                source.Position = 0;
            }
        }
Esempio n. 33
0
        public async void Play(int index, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            bool sameSong = index == SelectedIndex;

            SelectedIndex = index;
            var resourceItem = Items[index];

            // If paused, just unpause and play
            if (PlaybackState == PlaybackState.Paused)
            {
                Pause();
                return;
            }

            // If same song and stream is loaded, just JumpTo start and start play.
            if (sameSong && resourceItem.Stream != null && PlaybackState == PlaybackState.Playing)
            {
                JumpTo(TimeSpan.Zero);
                return;
            }

            Stop(false);

            Log(string.Format(@"Reading : '{0}'", resourceItem.DisplayName));
            var status = await _client.GetStreamAsync(resourceItem, cancellationToken);

            if (status != ResourceLoadStatus.Ok && status != ResourceLoadStatus.StreamExisting)
            {
                Log(string.Format(@"Reading error : {0}", status));
                return;
            }

            Log(string.Format(@"Reading done : {0}", status));

            _resourceItemQueue.Enqueue(resourceItem);

            string extension = new FileInfo(resourceItem.DisplayName).Extension.ToLowerInvariant();

            switch (extension)
            {
            case ".wav":
                _waveSource = new WaveFileReader(resourceItem.Stream);
                break;

            case ".mp3":
                _waveSource = new DmoMp3Decoder(resourceItem.Stream);
                break;

            case ".ogg":
                _waveSource = new NVorbisSource(resourceItem.Stream).ToWaveSource();
                break;

            case ".flac":
                _waveSource = new FlacFile(resourceItem.Stream);
                break;

            case ".wma":
                _waveSource = new WmaDecoder(resourceItem.Stream);
                break;

            case ".aac":
            case ".m4a":
            case ".mp4":
                _waveSource = new AacDecoder(resourceItem.Stream);
                break;

            default:
                throw new NotSupportedException(string.Format("Extension '{0}' is not supported", extension));
            }

            _soundOut.Initialize(_waveSource);
            _soundOut.Play();
            PlayStarted(SelectedIndex, resourceItem);

            // Preload Next
            PreloadNext(cancellationToken);
        }
Esempio n. 34
0
        private void CanHandleEOFTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            int sourceLength = (int)source.GetLength().TotalMilliseconds;
            Debug.WriteLine(soundOut.GetType().FullName);
            for (int i = 0; i < BasicIterationCount; i++)
            {
                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Pause();
                soundOut.Resume();

                Thread.Sleep(10);

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 1000);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                source.Position = 0;
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
            }
        }
Esempio n. 35
0
 private void RecordSilence()
 {
     m_soundOut = new WasapiOut();
     m_soundOut.Initialize(new SilenceGenerator());
     m_soundOut.Play();
 }
Esempio n. 36
0
        private void PlaybackStoppedEventTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            for (int i = 0; i < BasicIterationCount; i++)
            {
                bool raised = false;
                soundOut.Stopped += (s, e) => raised = true;

                //1. wait for the event on end of stream
                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep((int)(source.GetLength().TotalMilliseconds + 50));
                while (soundOut.PlaybackState != PlaybackState.Stopped)
                    Thread.Sleep(10);

                soundOut.Initialize(source); //the playbackstate may be stopped but event was not fired. initialize will wait until it gets fired.

                source.Position = 0;
                Assert.IsTrue(raised);
                raised = false;

                //2. event on Stop()
                soundOut.Play();

                Thread.Sleep(50);
                soundOut.Stop();

                Assert.IsTrue(raised);
            }
        }
Esempio n. 37
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var openFileDialog = new OpenFileDialog()
            {
                Filter = CodecFactory.SupportedFilesFilterEn,
                Title = "Select a file..."
            };
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                Stop();

                const FftSize fftSize = FftSize.Fft4096;

                IWaveSource source = CodecFactory.Instance.GetCodec(openFileDialog.FileName);

                var spectrumProvider = new BasicSpectrumProvider(source.WaveFormat.Channels,
                    source.WaveFormat.SampleRate, fftSize);
                _lineSpectrum = new LineSpectrum(fftSize)
                {
                    SpectrumProvider = spectrumProvider,
                    UseAverage = true,
                    BarCount = 50,
                    BarSpacing = 2,
                    IsXLogScale = true,
                    ScalingStrategy = ScalingStrategy.Sqrt
                };
                _voicePrint3DSpectrum = new VoicePrint3DSpectrum(fftSize)
                {
                    SpectrumProvider = spectrumProvider,
                    UseAverage = true,
                    PointCount = 200,
                    IsXLogScale = true,
                    ScalingStrategy = ScalingStrategy.Sqrt
                };

                var notificationSource = new SingleBlockNotificationStream(source.ToSampleSource());
                notificationSource.SingleBlockRead += (s, a) => spectrumProvider.Add(a.Left, a.Right);

                _source = notificationSource.ToWaveSource(16);

                _soundOut = new WasapiOut();
                _soundOut.Initialize(_source.ToMono());
                _soundOut.Play();

                timer1.Start();

                propertyGridTop.SelectedObject = _lineSpectrum;
                propertyGridBottom.SelectedObject = _voicePrint3DSpectrum;
            }
        }
Esempio n. 38
0
        private void PlayStopTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            for (int i = 0; i < BasicIterationCount; i++)
            {
                soundOut.Initialize(source);
                soundOut.Play();
                soundOut.Stop();
                soundOut.Initialize(source);
                soundOut.Play();
                soundOut.Stop();

                soundOut.Initialize(source);
                soundOut.Play();
                soundOut.Stop();
                soundOut.Initialize(source);
                soundOut.Play();
                soundOut.Stop();

                soundOut.Initialize(source);
                soundOut.Play();
                soundOut.Stop();
                soundOut.Initialize(source);
                soundOut.Play();
                soundOut.Stop();
            }
        }
Esempio n. 39
0
 private void buttonStart_Click(object sender, EventArgs e)
 {
     soundOut.Play();
 }
Esempio n. 40
0
        private void buttonCheck_Click(object sender, EventArgs e)
        {
            if (listViewSources.SelectedItems.Count > 0)
            {
                if (_soundIn == null)
                {
                    if (SelectedDevice == null)
                    {
                        return;
                    }

                    buttonCheck.Enabled = false;
                    if (captureMode == CaptureMode.Capture)
                    {
                        _soundIn = new WasapiCapture();
                    }
                    else
                    {
                        _soundIn = new WasapiLoopbackCapture(100, new WaveFormat(48000, 24, 2));
                    }

                    _soundIn.Device = SelectedDevice;
                    _soundIn.Initialize();

                    var soundInSource = new SoundInSource(_soundIn)
                    {
                        FillWithZeros = SelectedDevice.DeviceFormat.Channels <= 1 ? true : false
                    };

                    var singleBlockNotificationStream = new SingleBlockNotificationStream(soundInSource.ToStereo().ToSampleSource());
                    _finalSource = singleBlockNotificationStream.ToWaveSource();

                    singleBlockNotificationStream.SingleBlockRead += SingleBlockNotificationStreamOnSingleBlockRead;

                    _soundIn.Start();
                    if (captureMode == CaptureMode.Capture)
                    {
                        if (SelectedDevice.DeviceFormat.Channels <= 1)
                        {
                            _soundOut = new WasapiOut()
                            {
                                Device = new MMDeviceEnumerator().GetDefaultAudioEndpoint(DataFlow.Render, Role.Communications)
                            };
                        }
                        else
                        {
                            _soundOut = new WasapiOut();
                        }
                        _soundOut.Initialize(_finalSource);
                        _soundOut.Play();
                    }
                    else
                    {
                        byte[] buffer = new byte[_finalSource.WaveFormat.BytesPerSecond / 2];
                        soundInSource.DataAvailable += (s, ex) =>
                        {
                            int read;
                            while ((read = _finalSource.Read(buffer, 0, buffer.Length)) > 0)
                            {
                            }
                        };
                    }
                    buttonCheck.Enabled = true;
                    buttonRefreshMicro0phone.Enabled = false;
                    listViewSources.Enabled          = false;
                    checkBoxLoopback.Enabled         = false;
                    buttonCheck.Text = "Stop";
                }
                else
                {
                    buttonCheck.Enabled = false;
                    if (_soundOut != null)
                    {
                        _soundOut.Stop();
                        _soundOut.Dispose();
                        _soundOut = null;
                    }
                    if (_soundIn != null)
                    {
                        _soundIn.Stop();
                        _soundIn.Dispose();
                        _soundIn = null;
                    }
                    buttonCheck.Enabled              = true;
                    listViewSources.Enabled          = true;
                    buttonRefreshMicro0phone.Enabled = true;
                    checkBoxLoopback.Enabled         = true;
                    buttonCheck.Text = "Start";
                }
            }
            else
            {
                MessageBox.Show("Reload & Select a Device");
            }
        }
Esempio n. 41
0
        public Form1()
        {
            //MetroMessageBox.Show(this, string.Format("{0} - 1, {1} - 2, {2} - 3", StylesList[1], StylesList[2], StylesList[3]));
            InitializeComponent();

            #region Player Initialization
            player = GetSoundOut();
            playerInit = true;
            player.Stopped += new EventHandler<PlaybackStoppedEventArgs>(player_Stopped);
            #endregion

            LoadFromSettings();

            #region Settings Initialization
            for (int i = 1; i < Enum.GetNames(typeof(MetroColorStyle)).Length; i++)
                mcbStyles.Items.Add(StylesList[i]);
            mcbThemes.Items.Add(ThemesList[1]);
            mcbThemes.Items.Add(ThemesList[2]);
            mcbThemes.SelectedItem = msm.Theme;
            mcbStyles.SelectedItem = msm.Style;
            #endregion

            #region Taskbar Buttons Add & Delegates
            ttbbPlayPause.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(ttbbPlayPause_Click);
            ttbbNext.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(ttbbNext_Click);
            ttbbPrev.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(ttbbPrev_Click);
            ttbbForward.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(ttbbForward_Click);
            ttbbRewind.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(ttbbRewind_Click);

            TaskbarManager.Instance.ThumbnailToolBars.AddButtons(this.Handle, ttbbPrev, ttbbRewind, ttbbPlayPause, ttbbForward, ttbbNext);
            #endregion

            #region Song Initialization
            foreach (FileInfo fi in (new DirectoryInfo(Path.GetFullPath("TestMusic")).GetFiles()))
                Playlist.Add(fi.FullName);
            //TODO: MAKE IT WORKING!
            /*System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();
            pfc.AddFontFile(Path.GetFullPath("comfortaa.ttf"));
            Font = new Font(pfc.Families[0], Font.Size, Font.Style);
            foreach (Control c in Controls)
                c.Font = new Font(pfc.Families[0],c.Font.Size, c.Font.Style);*/
            GetAndFillWithSongInfo();

            source = CodecFactory.Instance.GetCodec(Playlist[ActualFileIndex]);
            ActualFileIndex = 0;
            player.Initialize(source);
            player.Play();
            mtbTime.Maximum = Convert.ToInt32(source.GetLength().TotalSeconds);
            mtbTime.Value = 0;
            t.Tick += new EventHandler(Tick);
            t.Start();
            #endregion

            //AddTrackToList(Playlist[0], Playlist[1]);
        }
Esempio n. 42
0
        public override void Run()
        {
//            lorImport.Start();
            soundOut.Play();
        }
Esempio n. 43
0
        private void PlayPauseResumeBehaviourTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            for (int i = 0; i < basic_iteration_count; i++)
            {
                soundOut.Initialize(source);
                //--

                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                Thread.Sleep(50);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Resume();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);
                //--
                Thread.Sleep(250);
                //--
                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                Thread.Sleep(50);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);
                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Resume();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);
                //--

                soundOut.Stop();
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                Thread.Sleep(10);

                soundOut.Stop();
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);


                //--
                soundOut.Stop();
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);
                source.Position = 0;
            }
        }