public void VolumeMaxCommandTest()
        {
            var playControlViewModel = new PlayControlViewModel();

            playControlViewModel.VolumeMaxCommand.Execute(new object());
            Assert.AreEqual(100, playControlViewModel.SliderVolumeValue);
        }
        public void SaveVolumeSettingTest()
        {
            var playControlViewModel = new PlayControlViewModel();
            var appConfig            = new AppConfiguration();

            playControlViewModel.SaveVolumeSetting(60);
            Assert.AreEqual(60, appConfig.ReadSetting("Volume"));
        }
        public void PlayNextSongAfterPreviousTest()
        {
            var playControlViewModel = new PlayControlViewModel();

            playControlViewModel.IsRepeatSong = false;
            playControlViewModel.index        = 0;
            playControlViewModel.PlayNextSongAfterPrevious();
            Assert.AreEqual(1, playControlViewModel.index);
        }
        public void GetActualSongSecondTest()
        {
            var playControlViewModel = new PlayControlViewModel();

            playControlViewModel.mediaPlayer.Open(new Uri(path));
            Assert.AreEqual(0, playControlViewModel.GetActualSongSecond());
            playControlViewModel.mediaPlayer.Position = TimeSpan.FromSeconds(50);
            Assert.AreEqual(50, playControlViewModel.GetActualSongSecond());
        }
        public void SetMediaPlayerVolumeTest()
        {
            var playControlViewModel = new PlayControlViewModel();

            Assert.AreEqual(100, playControlViewModel.SliderVolumeValue);
            playControlViewModel.SetMediaPlayerVolume(70);
            Assert.AreEqual(70, playControlViewModel.SliderVolumeValue);
            Assert.AreEqual(70, playControlViewModel.mediaPlayer.Volume * 100);
        }
        public void PauseSongTest()
        {
            var playControlViewModel = new PlayControlViewModel();

            Assert.IsFalse(playControlViewModel.IsPlay);
            playControlViewModel.PauseSong();
            Assert.IsFalse(playControlViewModel.IsPlay);
            playControlViewModel.IsPlay = true;
            Assert.IsTrue(playControlViewModel.IsPlay);
        }
        public void RandomSongTest()
        {
            var playControlViewModel = new PlayControlViewModel();

            Assert.IsFalse(playControlViewModel.IsRandomSong);
            playControlViewModel.RandomSongCommand.Execute(new object());
            Assert.IsTrue(playControlViewModel.IsRandomSong);
            playControlViewModel.RandomSongCommand.Execute(new object());
            Assert.IsFalse(playControlViewModel.IsRandomSong);
        }
        public void PlayPreviousSongTest()
        {
            var           playControlViewModel = new PlayControlViewModel();
            PlayListModel playListModel        = new PlayListModel();

            playListModel.SongPath = path;
            PlayListViewModel.ListBoxItems.Add(playListModel);
            playControlViewModel.PlayPreviousSongCommand.Execute(new object());
            Assert.IsNotNull(playControlViewModel.mediaPlayer.Source);
            playControlViewModel.mediaPlayer.Stop();
        }
        public void CalculateSliderValueTest()
        {
            var playControlViewModel = new PlayControlViewModel();

            Assert.AreEqual(0, playControlViewModel.CalculateSliderValue());
            playControlViewModel.mediaPlayer.Open(new Uri(path));
            Thread.Sleep(200);
            Assert.AreNotEqual(0, playControlViewModel.GetSongSecondsCount());
            playControlViewModel.mediaPlayer.Position = TimeSpan.FromSeconds(127);
            Assert.AreEqual(50, playControlViewModel.CalculateSliderValue());
        }
        public void GetSongSecondsCountTest()
        {
            var playControlViewModel = new PlayControlViewModel();

            Assert.AreEqual(0, playControlViewModel.GetSongSecondsCount());
            playControlViewModel.mediaPlayer.Open(new Uri(path));
            Thread.Sleep(200);
            Assert.AreEqual(254, playControlViewModel.GetSongSecondsCount());
            Assert.IsNotNull(playControlViewModel.mediaPlayer.Source);
            Assert.IsTrue(playControlViewModel.mediaPlayer.NaturalDuration.HasTimeSpan);
        }
        public void StopSongTest()
        {
            var playControlViewModel = new PlayControlViewModel();

            Assert.IsFalse(playControlViewModel.IsPlay);
            playControlViewModel.StopSongCommand.Execute(new object());
            Assert.IsFalse(playControlViewModel.IsPlay);
            Assert.IsTrue(playControlViewModel.IsStop);
            Assert.AreEqual("00:00", playControlViewModel.DurationMP3);
            Assert.AreEqual(0, playControlViewModel.SliderDurationValue);
        }
        public void SetMediaPlayerSongPositionTest()
        {
            var playControlViewModel = new PlayControlViewModel();

            playControlViewModel.mediaPlayer.Open(new Uri(path));
            Thread.Sleep(200);
            playControlViewModel.SliderDurationValue = 0;
            playControlViewModel.SetMediaPlayerSongPosition();
            Assert.AreEqual(0, playControlViewModel.GetActualSongSecond());
            playControlViewModel.SliderDurationValue = 2;
            playControlViewModel.SetMediaPlayerSongPosition();
            Assert.AreEqual(5, playControlViewModel.GetActualSongSecond());
        }
        public void PlaySongWithITest()
        {
            var playControlViewModel = new PlayControlViewModel();

            playControlViewModel.mediaPlayer.Open(null);
            Assert.IsNull(playControlViewModel.mediaPlayer.Source);
            playControlViewModel.PlaySongWithSpecificIndex(0);
            Assert.AreEqual(true, playControlViewModel.IsPlay);
            PlayListViewModel.ListBoxItems.Clear();
            playControlViewModel.mediaPlayer.Open(null);
            playControlViewModel.PlaySongWithSpecificIndex(0);
            Assert.IsNull(playControlViewModel.mediaPlayer.Source);
        }
        public void PlaySongTest()
        {
            var playControlViewModel = new PlayControlViewModel();

            playControlViewModel.mediaPlayer.Open(null);
            Assert.AreEqual("00:00", playControlViewModel.ElapsedTimeMP3);
            playControlViewModel.PlaySong();
            Assert.IsNull(playControlViewModel.mediaPlayer.Source);
            playControlViewModel.mediaPlayer.Open(new Uri(path));
            playControlViewModel.PlaySong();
            Assert.IsNotNull(playControlViewModel.mediaPlayer.Source);
            Assert.IsFalse(playControlViewModel.IsStop);
            playControlViewModel.mediaPlayer.Stop();
        }
        public void PlayOrPauseSongTest()
        {
            var playControlViewModel = new PlayControlViewModel();

            Assert.AreEqual(0, PlayListViewModel.ListBoxItems.Count);
            playControlViewModel.PlaySongCommand.Execute(new object());
            Assert.AreEqual(false, playControlViewModel.IsPlay);
            PlayListModel playListModel = new PlayListModel();

            playListModel.SongPath = path;
            PlayListViewModel.ListBoxItems.Add(playListModel);
            playControlViewModel.IsPlay = true;
            playControlViewModel.PlaySongCommand.Execute(new object());
            Assert.AreEqual(true, playControlViewModel.IsPlay);
        }
        public PlayControlView()
        {
            InitializeComponent();
            timer = new Timer();
            playControlViewModel = new PlayControlViewModel();
            this.DataContext     = playControlViewModel;

            playControlViewModel.mediaPlayer.MediaOpened += mediaPlayer_MediaOpened;
            playControlViewModel.mediaPlayer.MediaEnded  += mediaPlayer_MediaEnded;
            durationSlider.AddHandler(MouseLeftButtonUpEvent,
                                      new MouseButtonEventHandler(timeSlider_MouseLeftButtonUp),
                                      true);
            durationSlider.AddHandler(MouseLeftButtonDownEvent,
                                      new MouseButtonEventHandler(timeSlider_MouseLeftButtonDown),
                                      true);
        }
Ejemplo n.º 17
0
 private bool checkEqual(IUrl ui, PlayControlViewModel vm)
 {
     if (ui is ILocalUrl)
     {
         return(ui.LocalPath == vm.Source.LocalSourcePath);
     }
     else if (ui is IRemoteUrl)
     {
         IRemoteUrl ru = ui as IRemoteUrl;
         return(ru.SourceIp == vm.Source.Storage.Ip &&
                ru.SourcePort == vm.Source.Storage.Port &&
                ru.BeginTime == vm.PlaySlider.BeginTime &&
                ru.EndTime == vm.PlaySlider.EndTime);
     }
     return(false);
 }
        public void PlayNextSongTest()
        {
            var           playControlViewModel = new PlayControlViewModel();
            PlayListModel playListModel        = new PlayListModel();

            playListModel.SongPath = path;
            PlayListViewModel.ListBoxItems.Clear();
            PlayListViewModel.ListBoxItems.Add(playListModel);
            playControlViewModel.index = 10;
            playControlViewModel.PlayNextSongCommand.Execute(new object());
            Assert.AreEqual(0, playControlViewModel.index);
            playControlViewModel.index        = 0;
            playControlViewModel.IsRandomSong = true;
            playControlViewModel.PlayNextSongCommand.Execute(new object());
            Assert.AreEqual(0, playControlViewModel.index);
        }
Ejemplo n.º 19
0
 private void playVideoInfos(PlayControlViewModel vm, IUrl ui)
 {
     if (checkEqual(ui, vm))
     {
         foreach (VideoInfo vi in ui.VideoInfos)
         {
             if (!string.IsNullOrWhiteSpace(ui.LocalPath))
             {
                 string path = Path.Combine(ui.LocalPath, $"{vi.VideoId}_{vi.StreamId}");
                 if (!new DirectoryInfo(path).Exists)
                 {
                     Util.DialogUtil.ShowMessage(string.Format("未找到 \"{0}\" 视频!", vi.VideoName));
                     continue;
                 }
             }
             vm.AddToPlay(vi.VideoId, vi.StreamId, vi.VideoName);
         }
         vm.IsPlaying = true;
     }
 }
Ejemplo n.º 20
0
        private void initPlay(object uaiObj)
        {
            UrlAndIndex uai   = (UrlAndIndex)uaiObj;
            IUrl        ui    = uai.Url;
            int         index = uai.Index;

            if (ui.VideoInfos == null || ui.VideoInfos.Length == 0)
            {
                return;
            }
            while (index == VideoInfoManager.Instance.SourceIndex)
            {
                PlayControlViewModel vm = getPlayCtrlModel();
                if (vm.IsReadyToPlay())
                {
                    this.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        playVideoInfos(vm, ui);
                    }), null);
                    break;
                }
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 21
0
 public ExportUrlChecker(PlayControlViewModel vm)
 {
     _playVM = vm;
 }