예제 #1
0
        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);
        }
예제 #2
0
 public void CanCreateWaveOutDevice()
 {
     WaveOut waveOut = new WaveOut();
     var source = new SineGenerator().ToWaveSource(16);
     waveOut.Initialize(source);
     waveOut.Dispose();
 }
예제 #3
0
        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;
                }
            }
        }
예제 #4
0
 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;
     }
 }
예제 #5
0
파일: Program.cs 프로젝트: hoangduit/cscore
        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);
                        }
                    }
                }
            }
        }