Esempio n. 1
0
 public static void Stop()
 {
     PlayerNotification.Stop();
     player?.Stop();
     reader?.Dispose();
     player?.Dispose();
     ViewModelManager.MainWindowViewModel.SetStopState();
 }
Esempio n. 2
0
        public static async void Play()
        {
            //主页面设置缓冲中状态
            ViewModelManager.MainWindowViewModel.SetBufferState();
            //异步加载音乐
            await Task.Run(new Action(() =>
            {
                PrePlay();
            }));

            //主页面设置播放状态
            ViewModelManager.MainWindowViewModel.SetPlayState();

            try
            {
                if (State == PlaybackState.Stopped)
                {
                    reader     = new MediaFoundationReader(Source);
                    channel    = new SampleChannel(reader);
                    aggregator = new SampleAggregator(channel);
                    aggregator.NotificationCount = reader.WaveFormat.SampleRate / 100;
                    aggregator.PerformFFT        = true;
                    aggregator.FftCalculated    += DrawFFT;
                    player.Init(aggregator);
                }

                player.Play();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }


            //当前进度设置
            PlayerNotification.Start();

            if (!File.Exists(DownloadManager.MusicCachePath + PlayMusic.Id + ".tmp") && PlayMusic.Origin != Enum.MusicSource.Local)
            {
                DownloadManager.DownloadFileAsync(Source, DownloadManager.MusicCachePath, PlayMusic.Id + ".tmp");
            }
        }