public TorshifySongPlayer(string username = null, string password = null, bool rememberme = false) { if (Session == null) { Session = SessionFactory.CreateSession(Constants.ApplicationKey, Constants.CacheFolder, Constants.SettingsFolder, Constants.UserAgent) .SetPreferredBitrate(Bitrate.Bitrate320k); } Session.LoginComplete += (sender, eventArgs) => { wait.Set(); }; Session.MusicDeliver += _session_MusicDeliver; if (username != null && password != null) { Session.Login(username, password, rememberme); } else { Session.Relogin(); } _waveOut = new WaveOut(); wait.WaitOne(10000); }
public void CanCreateWaveOutDevice() { WaveOut waveOut = new WaveOut(); var source = new SineGenerator().ToWaveSource(16); waveOut.Initialize(source); waveOut.Dispose(); }
public void OpenFile(string path, ref EqualizerSounds _equalizer) { Stop(); if (ActiveStream != null) { SelectionBegin = TimeSpan.Zero; SelectionEnd = TimeSpan.Zero; ChannelPosition = 0; } StopAndCloseStream(); if (System.IO.File.Exists(path)) { try { // _soundOut.Initialize(source); waveOutDevice = new CSCore.SoundOut.WaveOut(100); //{ // DesiredLatency = 100 //}; ActiveStream = new Mp3FileReader(path); inputStream = new WaveChannel32(ActiveStream); sampleAggregator = new SampleAggregator(fftDataSize); inputStream.Sample += inputStream_Sample; //// inputStream.WaveFormat var source = CodecFactory.Instance.GetCodec(path) .Loop() .ChangeSampleRate(32000) .ToSampleSource() .AppendSource(EqualizerSounds.Create10BandEqualizer, out _equalizer) .ToWaveSource(); //waveOutDevice.Init(inputStream); waveOutDevice.Initialize(source); ChannelLength = inputStream.TotalTime.TotalSeconds; FileTag = TagLib.File.Create(path); GenerateWaveformData(path); CanPlay = true; } catch { ActiveStream = null; CanPlay = false; } } }
private void StopAndCloseStream() { if (waveOutDevice != null) { waveOutDevice.Stop(); } if (activeStream != null) { inputStream.Close(); inputStream = null; ActiveStream.Close(); ActiveStream = null; } if (waveOutDevice != null) { waveOutDevice.Dispose(); waveOutDevice = null; } }
static void Main(string[] args) { var openFileDialog = new OpenFileDialog(); openFileDialog.Filter = CodecFactory.SupportedFilesFilterEn; if (openFileDialog.ShowDialog() == DialogResult.OK) { using (var source1 = CodecFactory.Instance.GetCodec(openFileDialog.FileName)) { Debug.Assert(source1.CanSeek, "Source does not support seeking."); using (var soundOut = new WaveOut(150)) { var source = source1.ToSampleSource(); soundOut.Initialize(source.ToWaveSource()); soundOut.Play(); Console.WriteLine("Press any key to skip half the track."); Console.ReadKey(); source.Position = source.Length / 2; while (true) { IAudioSource s = source1; var str = String.Format(@"New position: {0:mm\:ss\.f}/{1:mm\:ss\.f}", TimeConverterFactory.Instance.GetTimeConverterForSource(s) .ToTimeSpan(s.WaveFormat, s.Position), TimeConverterFactory.Instance.GetTimeConverterForSource(s) .ToTimeSpan(s.WaveFormat, s.Length)); str += String.Concat(Enumerable.Repeat(" ", Console.BufferWidth - 1 - str.Length)); Console.Write(str); Console.SetCursorPosition(0, Console.CursorTop); } } } } }