public (int index, IPlayableId id)? NextPlayableDoNotSet() { if (_state.ConnectState.Options.RepeatingTrack) { return((int)GetCurrentTrackIndex(), PlayableId.From(Tracks[(int)GetCurrentTrackIndex()])); } if (_queue.Any()) { return(-1, PlayableId.From(_queue.First())); } int current = (int)GetCurrentTrackIndex(); if (current == Tracks.Count - 1) { if (_state.IsShufflingContext() || _cannotLoadMore) { return(null); } if (_state.Pages.NextPage()) { Tracks.AddRange(_state.Pages.CurrentPage()); } else { _cannotLoadMore = true; UpdateTrackCount(); return(null); } } if (!_state.Context.IsFinite() && Tracks.Count - current <= 5) { if (_state.Pages.NextPage()) { Tracks.AddRange(_state.Pages.CurrentPage()); Debug.WriteLine("Preloaded next page due to infinite context."); } else { Debug.WriteLine("Couldn't (pre)load next page of context!"); } } int add = 1; while (true) { var track = Tracks[current + add]; if (ShouldPlay(track)) { break; } add++; } return(current + add, PlayableId.From(Tracks[(current + add)])); }
public void InitializeStart() { if (!_state.Pages.NextPage()) { throw new Exception("Illegal State"); } Tracks.Clear(); Tracks.AddRange(_state.Pages.CurrentPage()); CheckComplete(); if (!PlayableId.CanPlaySomething(Tracks)) { throw new Exception("UnsupportedContextException"); } var transformingShuffle = _state.ConnectState.ContextMetadata.ContainsKey("transform.shuffle"); transformingShuffle = transformingShuffle && bool.Parse(_state.ConnectState.ContextMetadata["transform.shuffle"]); if (_state.Context.IsFinite() && _state.IsShufflingContext() && transformingShuffle) { ShuffleEntirely(); } else { _state.ConnectState.Options.ShufflingContext = false; // Must do this directly! } SetCurrentTrackIndex(0); }
public void InitializeFrom( [NotNull] Func <List <ContextTrack>, int> finder, [CanBeNull] ContextTrack track, [CanBeNull] Queue contextQueue) { Tracks.Clear(); _queue.Clear(); while (true) { if (_state.Pages.NextPage()) { var newTracks = _state.Pages.CurrentPage(); var index = finder(newTracks); if (index == -1) { Tracks.AddRange(newTracks); continue; } index += Tracks.Count(); Tracks.AddRange(newTracks); SetCurrentTrackIndex(index); break; } else { _cannotLoadMore = true; UpdateTrackCount(); throw new Exception("Couldn't find current track!"); } } if (contextQueue != null) { foreach (var t in contextQueue.Tracks) { _queue.Add(t); } _isPlayingQueue = contextQueue.IsPlayingQueue; UpdateState(); } CheckComplete(); if (!PlayableId.CanPlaySomething(Tracks)) { throw new Exception("Cannot play anything"); } if (track != null) { EnrichCurrentTrack(track); } }
public bool ShouldPlay([NotNull] ContextTrack track) { if (!PlayableId.IsSupported(track.Uri) || !PlayableId.ShouldPlay(track)) { return(false); } var filterExplicit = _state.Session.UserAttributes.ContainsKey("filter-explicit-content"); filterExplicit = !filterExplicit || bool.Parse(_state.Session.UserAttributes["filter-explicit-content"]); if (!filterExplicit) { return(true); } return(!bool.Parse(track.Metadata.ContainsKey("is_explicit") ? track.Metadata["is_explicit"] : "false")); }
public TrackOrEpisode([CanBeNull] Track track, [CanBeNull] Episode episode) { if (track == null && episode == null) { throw new ArgumentOutOfRangeException(); } this.track = track; this.episode = episode; if (track != null) { id = PlayableId.From(track); } else { id = PlayableId.From(episode); } }
public override int GetHashCode() { int hash = 1; if (SeriesId != 0) { hash ^= SeriesId.GetHashCode(); } if (EpisodeFileId != 0) { hash ^= EpisodeFileId.GetHashCode(); } if (SeasonNumber != 0) { hash ^= SeasonNumber.GetHashCode(); } if (EpisideNumber != 0) { hash ^= EpisideNumber.GetHashCode(); } if (Title.Length != 0) { hash ^= Title.GetHashCode(); } if (Overview.Length != 0) { hash ^= Overview.GetHashCode(); } if (PlayableId.Length != 0) { hash ^= PlayableId.GetHashCode(); } if (progress_ != null) { hash ^= Progress.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public IPlayableId GetCurrentPlayable() => ConnectState.Track == null ? null : PlayableId.From(ConnectState.Track);