Пример #1
0
 public void Dispose()
 {
     DontUpdatePosition = true;
     CurrentPosition    = 0;
     UpcomingSong       = null;
     timer.Stop();
     ShuffledList?.Clear();
     PlayPauseIcon = new SymbolIcon(Symbol.Play);
 }
Пример #2
0
 public CurrentPlaylistViewModel()
 {
     LaunchTrack = new UiCommand(o =>
     {
         PlayOffset = _shuffled ? ShuffledList.FindIndex(track => track.Track == o as TrackDefinition) : Current.Tracks.FindIndex(track => track.Track == o as TrackDefinition);
         Dispatch("Play", CurrentMedia);
         RefreshDisplay();
     }, o => Current != null);
 }
Пример #3
0
 public void Reset()
 {
     PlaylistSongCollection?.Clear();
     TracksCollection?.Clear();
     DontUpdatePosition = true;
     CurrentPosition    = 0;
     UpcomingSong       = null;
     timer.Stop();
     ShuffledList?.Clear();
     PlayPauseIcon = new SymbolIcon(Symbol.Play);
 }
Пример #4
0
 public void SetCurrentPlaylist(Playlist playlist)
 {
     Current    = playlist;
     PlayOffset = 0;
     if (_shuffled)
     {
         PlayOffset = ShuffledList.FindIndex(member => member.Position == Current.Tracks[PlayOffset].Position);
     }
     Current = Current;
     Dispatch("Play", CurrentMedia);
     RefreshDisplay();
 }
Пример #5
0
        public async Task <Mediafile> GetUpcomingSong(bool isNext = false)
        {
            var playingCollection = GetPlayingCollection();

            if (playingCollection != null && playingCollection.Any())
            {
                try
                {
                    int IndexOfCurrentlyPlayingFile = -1;
                    if (playingCollection.Any(t => t.State == PlayerState.Playing))
                    {
                        IndexOfCurrentlyPlayingFile = playingCollection.IndexOf(playingCollection.SingleOrDefault(t => t.State == PlayerState.Playing));
                    }
                    Mediafile toPlayFile = null;
                    if (Shuffle)
                    {
                        if (ShuffledList.Count < playingCollection.Count)
                        {
                            ShuffledList = await ShuffledCollection();

                            IndexOfCurrentlyPlayingFile = 0;
                        }
                        toPlayFile = ShuffledList?.ElementAt(IndexOfCurrentlyPlayingFile + 1);
                    }
                    else if (IsSourceGrouped)
                    {
                        toPlayFile = GetNextSongInGroup();
                    }
                    else
                    {
                        toPlayFile = IndexOfCurrentlyPlayingFile <= playingCollection.Count - 2 && IndexOfCurrentlyPlayingFile != -1 ? playingCollection.ElementAt(IndexOfCurrentlyPlayingFile + 1) : Repeat == "Repeat List" || isNext?playingCollection.ElementAt(0) : null;
                    }
                    return(toPlayFile);
                }
                catch (Exception ex)
                {
                    BLogger.Logger.Error("An error occured while trying to play next song.", ex);
                    await NotificationManager.ShowMessageAsync("An error occured while trying to play next song. Trying again...");

                    TracksCollection?.Elements.Where(t => t.State == PlayerState.Playing).ToList().ForEach(new Action <Mediafile>((Mediafile file) => { file.State = PlayerState.Stopped; }));
                    PlaylistSongCollection?.Where(t => t.State == PlayerState.Playing).ToList().ForEach(new Action <Mediafile>((Mediafile file) => { file.State = PlayerState.Stopped; }));
                    PlayNext();

                    return(null);
                }
            }
            return(null);
        }
Пример #6
0
        public void MultipleAddToPlaylistAndPlay(IEnumerable <TrackDefinition> tracks, int index)
        {
            Current = new Playlist();
            var off = Current.Tracks.Count + index;

            foreach (var track1 in tracks)
            {
                Current.AddTrack(track1);
            }
            PlayOffset = off;
            if (_shuffled)
            {
                PlayOffset = ShuffledList.FindIndex(member => member.Position == Current.Tracks[PlayOffset].Position);
            }
            Current = Current;
            Dispatch("Play", CurrentMedia);
            RefreshDisplay();
        }
Пример #7
0
        void PlayNext()
        {
            if (Player.CurrentlyPlayingFile != null)
            {
                history.Do(Player.CurrentlyPlayingFile);
            }
            int       IndexOfCurrentlyPlayingFile = GetListBox().Items.IndexOf(GetListBox().Items.Single(t => (t as Mediafile).State == PlayerState.Playing));
            Mediafile toPlayFile = null;

            if (Shuffle)
            {
                toPlayFile = ShuffledList.ElementAt(IndexOfCurrentlyPlayingFile + 1);
            }
            else
            {
                toPlayFile = IndexOfCurrentlyPlayingFile <= GetListBox().Items.Count - 2 ? GetListBox().Items.ElementAt(IndexOfCurrentlyPlayingFile + 1) as Mediafile : GetListBox().Items.ElementAt(0) as Mediafile;
            }
            PlayFile(toPlayFile);
        }
Пример #8
0
 public void MultipleAddToPlaylist(IEnumerable <TrackDefinition> tracks)
 {
     if (Current == null)
     {
         MultipleAddToPlaylistAndPlay(tracks, 0);
         return;
     }
     foreach (var track in tracks)
     {
         Current.AddTrack(track);
     }
     _currentTracks.Source = Current.Tracks;
     _shuffledList         = null;
     if (_shuffled)
     {
         PlayOffset = ShuffledList.FindIndex(member => member.Position == Current.Tracks[PlayOffset].Position);
     }
     CurrentTracks.Refresh();
     OnPropertyChanged(nameof(CurrentTracks));
 }
Пример #9
0
        void PlayNext()
        {
            Mediafile toPlayFile = null;

            if (Shuffle)
            {
                if (ShuffledList == null)
                {
                    ShuffledList = ShuffledCollection();
                }
                var playlingFile = LibVM.TracksCollection.Elements.Single(t => t.State == PlayerState.Playing);
                var index        = LibVM.TracksCollection.Elements.IndexOf(playlingFile) + 1;
                toPlayFile = ShuffledList.ElementAt(index);
            }
            else
            {
                LibVM.FileListBox.SelectedIndex = LibVM.FileListBox.SelectedIndex <= LibVM.FileListBox.Items.Count - 2 ? LibVM.FileListBox.SelectedIndex + 1 : 0;
                toPlayFile = LibVM.FileListBox.SelectedItem as Mediafile;
            }
            PlayFile(toPlayFile);
        }
Пример #10
0
        public async Task <Mediafile> GetUpcomingSong()
        {
            var playingCollection = GetPlayingCollection();

            if (playingCollection != null && playingCollection.Any())
            {
                try
                {
                    int IndexOfCurrentlyPlayingFile = -1;
                    if (playingCollection.Any(t => t.State == PlayerState.Playing))
                    {
                        IndexOfCurrentlyPlayingFile = playingCollection.IndexOf(playingCollection.SingleOrDefault(t => t.State == PlayerState.Playing));
                    }
                    Mediafile toPlayFile = null;
                    if (Shuffle)
                    {
                        if (!ShuffledList.Any())
                        {
                            ShuffledList = await ShuffledCollection().ConfigureAwait(false);

                            IndexOfCurrentlyPlayingFile = 0;
                        }
                        toPlayFile = ShuffledList?.ElementAt(IndexOfCurrentlyPlayingFile + 1);
                    }
                    else
                    {
                        toPlayFile = IndexOfCurrentlyPlayingFile <= playingCollection.Count - 2 && IndexOfCurrentlyPlayingFile != -1 ? playingCollection.ElementAt(IndexOfCurrentlyPlayingFile + 1) : Repeat == "Repeat List" ? playingCollection.ElementAt(0) : null;
                    }
                    return(toPlayFile);
                }
                catch (Exception ex)
                {
                    await NotificationManager.ShowAsync(ex.Message);

                    return(null);
                }
            }
            return(null);
        }
Пример #11
0
        /// <summary>
        /// Initializes the list and populates it with one agent of each type.
        /// </summary>
        public AgentList()
        {
            OrderedList  = new();
            ShuffledList = new();
            Dictionary   = new();
            PlayerAgents = new();

            foreach (Type type in GameService.AGENT_TYPES_ORDERED)
            {
                Agent agent = type.Instantiate <Agent>();

                OrderedList.Add(agent);
                ShuffledList.Add(agent);
                Dictionary.Add(type.Name, agent);

                if (agent is PlayerAgent playerAgent)
                {
                    PlayerAgents.Add(playerAgent);
                }
            }

            ShuffledList.Shuffle(GameService.Random);
        }
Пример #12
0
 private void RefreshDisplay()
 {
     if (Current.Tracks.Count > 50)
     {
         _currentTracks.Source = !_shuffled?Current.Tracks.Skip(PlayOffset).Take(50) : ShuffledList.Skip(PlayOffset).Take(50);
     }
     else if (Current.Tracks.Count - PlayOffset < 50)
     {
         _currentTracks.Source = !_shuffled?Current.Tracks.Skip(Math.Max(0, Current.Tracks.Count - 50)) : ShuffledList.Skip(Math.Max(0, Current.Tracks.Count - 50));
     }
     else
     {
         _currentTracks.Source = !_shuffled ? (IEnumerable <Playlist.Member>)Current.Tracks : ShuffledList;
     }
     CurrentTracks.Refresh();
     OnPropertyChanged(nameof(CurrentTracks));
 }