Example #1
0
        public static void RefreshTrackQueue(object obj)
        {
            var track = new PlayHistoryViewModel();

            _playList         = PlayListController.Instance;
            _player           = MediaPlayerController.Instance;
            _jukeboxAutoqueue = JukeBoxController.Instance;
            using (var uow = new Uow(new MusicFarmerEntities()))
            {
                var repoVotes = new RepositoryVote(uow);
                InitializeRepos(uow);
                SetPlayerSettings();
                SetJukeBoxSettings();
                if (_player.IsMuted)
                {
                    return;
                }

                if (!_player.IsPlaying())
                {
                    ChangeTrack();
                }

                if (_playList.IsPlayingTrack() && !(_player.IsPlaying()))
                {
                    track = _playList.GetPlayingTrack();
                }
                else if ((_player.IsPlaying()) && (!(_playList.IsPlayingTrack())))
                {
                    //Trust me on this one.
                    //___________________________________________________
                    //| Stop the track to resync the DB with the Player  |
                    //|__________________________________________________|

                    _player.Stop();
                    _jukeboxAutoqueue.IncrementPosition();
                    return;
                }
                else if (_playList.HasTrackQueued() && !(_player.IsPlaying()))
                {
                    track = _playList.GetNextQueuedTrack();
                }
                else if (!_player.IsPlaying())
                {
                    SpinUpJukeBox();
                    return;
                }


                if (_player.IsPlaying())
                {
                    track = _playList.GetPlayingTrack();
                    SetPlayerVolumeBasedOnVotes(repoVotes.GetUpVotes(track.PlayHistoryId).Count, repoVotes.GetDownVotes(track.PlayHistoryId).Count);
                }
                else
                {
                    LoadNewTrack(track);
                }
            }
        }