public void Dispose() { DontUpdatePosition = true; CurrentPosition = 0; UpcomingSong = null; timer.Stop(); ShuffledList?.Clear(); PlayPauseIcon = new SymbolIcon(Symbol.Play); }
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); }
public void Reset() { PlaylistSongCollection?.Clear(); TracksCollection?.Clear(); DontUpdatePosition = true; CurrentPosition = 0; UpcomingSong = null; timer.Stop(); ShuffledList?.Clear(); PlayPauseIcon = new SymbolIcon(Symbol.Play); }
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(); }
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); }
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(); }
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); }
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)); }
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); }
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); }
/// <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); }
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)); }