Пример #1
0
        public async Task <EnqueueResult> AddToQueueNextAsync(IList <PlayableTrack> tracks)
        {
            EnqueueResult result = await this.queueManager.EnqueueNextAsync(tracks, this.shuffle);

            this.QueueChanged(this, new EventArgs());

            if (result.EnqueuedTracks != null && result.IsSuccess)
            {
                this.AddedTracksToQueue(result.EnqueuedTracks.Count);
            }

            this.ResetSaveQueuedTracksTimer(); // Save queued tracks to the database

            return(result);
        }
Пример #2
0
        public async Task <EnqueueResult> EnqueueNextAsync(IList <PlayableTrack> tracks)
        {
            var result = new EnqueueResult {
                IsSuccess = true
            };

            try
            {
                await Task.Run(() =>
                {
                    lock (this.queueLock)
                    {
                        int queueIndex         = 0;
                        int playbackOrderIndex = 0;

                        if (!this.currentTrack.Equals(default(KeyValuePair <string, PlayableTrack>)))
                        {
                            queueIndex         = this.queue.IndexOf(this.currentTrack.Key);
                            playbackOrderIndex = this.playbackOrder.IndexOf(this.currentTrack.Key);
                        }

                        var kvp = new List <KeyValuePair <string, PlayableTrack> >();

                        foreach (PlayableTrack track in tracks)
                        {
                            kvp.Add(new KeyValuePair <string, PlayableTrack>(Guid.NewGuid().ToString(), track));
                        }

                        this.queue.InsertRange(queueIndex + 1, kvp);
                        this.playbackOrder.InsertRange(playbackOrderIndex + 1, kvp.Select(t => t.Key));

                        result.EnqueuedTracks = tracks;
                    }
                });
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                LogClient.Error("Error while enqueuing tracks next. Exception: {0}", ex.Message);
            }


            return(result);
        }
Пример #3
0
        public async Task <EnqueueResult> EnqueueAsync(IList <PlayableTrack> tracks, bool shuffle)
        {
            var result = new EnqueueResult {
                IsSuccess = true
            };

            try
            {
                await Task.Run(() =>
                {
                    lock (this.queueLock)
                    {
                        foreach (PlayableTrack track in tracks)
                        {
                            this.queue.Add(Guid.NewGuid().ToString(), track);
                        }

                        result.EnqueuedTracks = tracks;
                    }
                });

                if (shuffle)
                {
                    await this.ShuffleAsync();
                }
                else
                {
                    await this.UnShuffleAsync();
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                LogClient.Error("Error while enqueuing tracks. Exception: {0}", ex.Message);
            }


            return(result);
        }
Пример #4
0
        public async Task <EnqueueResult> EnqueueAsync(IList <KeyValuePair <string, PlayableTrack> > tracks, bool shuffle)
        {
            var result = new EnqueueResult {
                IsSuccess = true
            };

            try
            {
                await Task.Run(() =>
                {
                    lock (this.queueLock)
                    {
                        foreach (KeyValuePair <string, PlayableTrack> track in tracks)
                        {
                            this.queue.Add(track.Key, track.Value);
                        }

                        result.EnqueuedTracks = tracks.Select(t => t.Value).ToList();
                    }
                });

                if (shuffle)
                {
                    await this.ShuffleAsync();
                }
                else
                {
                    await this.UnShuffleAsync();
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                LogClient.Error("Error while enqueuing tracks. Exception: {0}", ex.Message);
            }

            return(result);
        }