internal NextRequested(
     [CanBeNull] IPlayableId track,
     NextType type)
 {
     Track    = track;
     NextType = type;
 }
        /// <summary>
        /// start playing this content by any possible mean. Also sets up crossfade for the previous entry and the current head.
        /// </summary>
        /// <param name="playable">The content to be played</param>
        /// <param name="pos">The time in milliseconds</param>
        /// <param name="reason">The reason why the playback started</param>
        /// <returns>The playback ID associated with the head</returns>
        public async Task <string> Play([NotNull] IPlayableId playable,
                                        int pos,
                                        [NotNull] Reason reason)
        {
            var j = (await PlayInternal(playable, pos, reason));

            return(j.item.PlaybackId);
        }
        /// <summary>
        /// Creates and adds a new entry to the queue.
        /// </summary>
        /// <param name="playable"></param>
        /// <param name="preloaded"></param>
        private void Add([NotNull] IPlayableId playable,
                         bool preloaded,
                         int initialSeek)
        {
            var entry = new PlayerQueueEntry(sink, playable, preloaded, this, initialSeek);

            queue.Add(entry);
            if (queue.Next() == entry)
            {
                var head = queue.Head;
            }
        }
        private async Task <(int entry, PlayerQueueEntry item)> PlayInternal(
            [NotNull] IPlayableId playable,
            int pos,
            [NotNull] Reason reason)
        {
            SpotifyPlayer.Current.State.SpotifyDevice.OnCurrentlyPlayingChanged(new PlayingChangedRequest
            {
                IsPaused   = false,
                ItemUri    = playable.Uri,
                IsPlaying  = true,
                ContextUri = SpotifyPlayer.Current.State.ConnectState.ContextUri
            });
            lastPlayPos    = pos;
            lastPlayReason = reason;

            if (!AdvanceTo(playable))
            {
                Add(playable, false, pos);
                queue.Advance();
            }

            var head = queue.Head;

            if (head == null)
            {
                throw new Exception("Illegal State");
            }

            var customFade = false;

            if (head.Prev != null)
            {
                head.Prev?.Dispose();
                customFade = false;
                //TODO: Crossfade
            }

            var @out = sink;

            if (@out == null)
            {
                throw new Exception("No output is available for " + head);
            }
            await head.Seek(pos);

            Debug.WriteLine("{0} has been added to the output. sessionId: {0}, pos: {1}, reason: {2}", head, sessionId, pos,
                            reason);
            return(pos, queue.Head);
        }
        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);
            }
        }
 /// <summary>
 /// Tries to advance to the given content. This is a destructive operation as it will close every entry that passes by.
 /// Also checks if the next entry has the same content, in that case it advances (repeating track fix).
 /// </summary>
 /// <returns>Whether the operation completed</returns>
 private bool AdvanceTo([NotNull] IPlayableId id)
 {
     do
     {
         var entry = queue.Head;
         if (entry == null)
         {
             return(false);
         }
         if (!entry.Playable.Equals(id))
         {
             continue;
         }
         var next = queue.Next();
         if (next == null || !next.Playable.Equals(id))
         {
             return(true);
         }
     } while (queue.Advance());
     return(false);
 }
        public PlayerQueueEntry(
            [NotNull] ISpotifyDevice sink,
            [NotNull] IPlayableId playable,
            bool preloaded,
            [NotNull] IPlayerQueueEntryListener listener,
            int initialSeek)
        {
            this.sink       = sink;
            Playable        = playable;
            this.preloaded  = preloaded;
            this.listener   = listener;
            previousCommand = null;
            this.PlaybackId = SpotifyState.GeneratePlaybackId();
            _current        = playable;
            Debug.WriteLine($"Created new {this}");

            this.sink.PlaybackStateChanged += PlaybackSession_PlaybackStateChanged;
            this.sink.MediaOpened          += MediaPlayer_MediaOpened;
            this.sink.MediaEnded           += MediaPlayer_MediaEnded;
            listener.StartedLoading(this);
            _ = Load(preloaded, initialSeek);
        }
 public Dictionary <string, string> MetadataFor(IPlayableId playable)
 {
     throw new NotImplementedException();
 }
Exemple #9
0
 public void OnSkipPrevious(IPlayableId prv)
 {
     SkipPrevious?.Invoke(this, prv);
 }