Example #1
0
        public async Task <TrackViewModel> NextTrackAsync(LoopMode loopMode, bool returnToStart)
        {
            TrackViewModel nextTrack = null;

            await Task.Run(() =>
            {
                try
                {
                    lock (this.queueLock)
                    {
                        if (this.playbackOrder != null && this.playbackOrder.Count > 0)
                        {
                            int currentTrackIndex = this.FindPlaybackOrderIndex(this.currentTrack);

                            if (loopMode.Equals(LoopMode.One))
                            {
                                // Return the current track
                                nextTrack = this.queue[this.playbackOrder[currentTrackIndex]];
                            }
                            else
                            {
                                if (currentTrackIndex < this.playbackOrder.Count - 1)
                                {
                                    // If we didn't reach the end of the queue, return the next track.
                                    int increment = 1;

                                    nextTrack = this.queue[this.playbackOrder[currentTrackIndex + increment]];

                                    // HACK: voids getting stuck on the same track when the playlist contains the same track multiple times
                                    while (this.currentTrack.Path.Equals(nextTrack.Path))
                                    {
                                        increment++;
                                        nextTrack = this.queue[this.playbackOrder[currentTrackIndex + increment]];
                                    }
                                }
                                else if (loopMode.Equals(LoopMode.All) | returnToStart)
                                {
                                    // When LoopMode.All is enabled, when we reach the end of the queue, return the first track.
                                    nextTrack = this.queue[this.playbackOrder.First()];
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogClient.Error("Could not get next track. Exception: {0}", ex.Message);
                }
            });

            return(nextTrack);
        }
Example #2
0
        public async Task <KeyValuePair <string, PlayableTrack> > NextTrackAsync(LoopMode loopMode, bool returnToStart)
        {
            KeyValuePair <string, PlayableTrack> nextTrack = default(KeyValuePair <string, PlayableTrack>);

            await Task.Run(() =>
            {
                try
                {
                    lock (this.queueLock)
                    {
                        if (this.playbackOrder != null && this.playbackOrder.Count > 0)
                        {
                            int currentTrackIndex = this.playbackOrder.IndexOf(this.currentTrack.Key);

                            if (loopMode.Equals(LoopMode.One))
                            {
                                // Return the current track
                                nextTrack = new KeyValuePair <string, PlayableTrack>(this.playbackOrder[currentTrackIndex], this.queue[this.playbackOrder[currentTrackIndex]]);
                            }
                            else
                            {
                                if (currentTrackIndex < this.playbackOrder.Count - 1)
                                {
                                    // If we didn't reach the end of the queue, return the next track.
                                    nextTrack = new KeyValuePair <string, PlayableTrack>(this.playbackOrder[currentTrackIndex + 1], this.queue[this.playbackOrder[currentTrackIndex + 1]]);
                                }
                                else if (loopMode.Equals(LoopMode.All) | returnToStart)
                                {
                                    // When LoopMode.All is enabled, when we reach the end of the queue, return the first track.
                                    nextTrack = new KeyValuePair <string, PlayableTrack>(this.playbackOrder.First(), this.queue[this.playbackOrder.First()]);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogClient.Error("Could not get next track. Exception: {0}", ex.Message);
                }
            });

            return(nextTrack);
        }
Example #3
0
        public async Task <TrackViewModel> NextTrackAsync(LoopMode loopMode, bool returnToStart)
        {
            TrackViewModel nextTrack = null;

            await Task.Run(() =>
            {
                try
                {
                    lock (this.queueLock)
                    {
                        if (this.playbackOrder != null && this.playbackOrder.Count > 0)
                        {
                            int currentTrackIndex = this.FindPlaybackOrderIndex(this.currentTrack);

                            if (loopMode.Equals(LoopMode.One))
                            {
                                // Return the current track
                                nextTrack = this.queue[this.playbackOrder[currentTrackIndex]];
                            }
                            else
                            {
                                if (currentTrackIndex < this.playbackOrder.Count - 1)
                                {
                                    // If we didn't reach the end of the queue, return the next track.
                                    nextTrack = this.queue[this.playbackOrder[currentTrackIndex + 1]];
                                }
                                else if (loopMode.Equals(LoopMode.All) | returnToStart)
                                {
                                    // When LoopMode.All is enabled, when we reach the end of the queue, return the first track.
                                    nextTrack = this.queue[this.playbackOrder.First()];
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogClient.Error("Could not get next track. Exception: {0}", ex.Message);
                }
            });

            return(nextTrack);
        }