Esempio n. 1
0
        private async Task DequeueSong()
        {
            // If the player is already playing a song, return
            if (IsPlaying)
            {
                return;
            }

            // Check if there are still request on the queue
            if (songs.Count == 0)
            {
                PlayerStopped?.Invoke(this);
                return;
            }

            BaseSong nextSong   = songs.Dequeue();
            Song     songToPlay = null;

            if (nextSong is YoutubePlaylistSong yps)
            {
                songToPlay = await GetSongFromUrl(yps.WebpageUrl);

                songToPlay.Requester = nextSong.Requester;
            }
            else if (nextSong is Song song)
            {
                songToPlay = song;
            }

            PlayerStarted?.Invoke(this, songToPlay);
            var _ = PlaySong(songToPlay);
        }
Esempio n. 2
0
 private void DeleteQueueSong(BaseSong song)
 {
     if (song != null)
     {
         _queueController.RemoveSongToQueue(song);
     }
 }
Esempio n. 3
0
        private void Ls_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            // Get the current mouse position
            Point  mousePos = e.GetPosition(null);
            Vector diff     = startPoint - mousePos;

            var lm = Mouse.LeftButton;

            if (lm == MouseButtonState.Pressed &&
                (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                 Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
            {
                // Get the dragged ListViewItem
                ListView     listView     = sender as ListView;
                ListViewItem listViewItem =
                    FindAnchestor <ListViewItem>((DependencyObject)e.OriginalSource);

                if (listViewItem == null)
                {
                    return;
                }

                // Find the data behind the ListViewItem
                BaseSong contact = (BaseSong)listView.ItemContainerGenerator.
                                   ItemFromContainer(listViewItem);

                // Initialize the drag & drop operation
                DataObject dragData = new DataObject("myFormat", contact);
                DragDrop.DoDragDrop(listViewItem, dragData, DragDropEffects.Move);
            }
        }
Esempio n. 4
0
 public void AddSongToQueue(BaseSong song)
 {
     Queue.Songs.Add(song);
     song.PlaylistId = Queue.Id;
     //song.PlaylistNr = Queue.Songs.IndexOf(song);
     PlaylistChangedEvent?.Invoke(this, new PlaylistChangedEventArgs());
     if (CurrentSong == null)
     {
         CurrentSong = song;
     }
 }
Esempio n. 5
0
        public YoutubeSong ToYoutubeSong(BaseSong song)
        {
            var res = song as YoutubeSong;

            if (res == null)
            {
                throw new ArgumentException("This service can only work with youtube songs.");
            }

            return(res);
        }
Esempio n. 6
0
        public static PlaylistItem FromXmlContract(BaseSong contract)
        {
            if (contract == null)
            {
                return(null);
            }

            return(new PlaylistItem
            {
                Artist = contract.Artist,
                Title = contract.Title,
                Time = contract.Start
            });
        }
Esempio n. 7
0
        public void SaveSong(BaseSong song, Playlist playlist)
        {
            var ySong   = ToYoutubeSong(song);
            var command = _c.CreateCommand();

            command.CommandText = $"replace into {YoutubeTableName} " +
                                  $"values (@sid,@nr,@pid,@title)";
            command.Parameters.Add(new SQLiteParameter("@sid", ySong.VideoId));
            command.Parameters.Add(new SQLiteParameter("@nr", ySong.PlaylistNr));
            command.Parameters.Add(new SQLiteParameter("@pid", playlist.Id));
            command.Parameters.Add(new SQLiteParameter("@title", ySong.Title));

            var affected = command.ExecuteNonQuery();
        }
Esempio n. 8
0
        private void Ls_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("myFormat"))
            {
                BaseSong contact  = e.Data.GetData("myFormat") as BaseSong;
                ListView listView = sender as ListView;
                var      source   = ((IList <BaseSong>)listView.ItemsSource);

                var location = IndexUnderDragCursor;
                if (location == -1)
                {
                    return;
                }

                source.Remove(contact);
                source.Insert(location, contact);
            }
        }
Esempio n. 9
0
        public void CurrentSong_set_NewRaiseEvent()
        {
            var              eventRaised = false;
            BaseSong         songSent    = null;
            IQueueController controller  = new QueueController();

            controller.CurrentSongChangedEvent += delegate(object s, SongChangedEventArgs model)
            {
                eventRaised = true;
                songSent    = model.CurrentSong;
            };
            var songStub = new TestSong();

            controller.CurrentSong = songStub;

            Assert.IsTrue(eventRaised);
            Assert.AreSame(songSent, songStub);
        }
Esempio n. 10
0
        public void RemoveSong(BaseSong song, Playlist playlist)
        {
            var ySong = ToYoutubeSong(song);

            using (var command = _c.CreateCommand())
            {
                command.CommandText = $"delete from {YoutubeTableName} where " +
                                      $"{PlaylistIdColumnName} = @plid and " +
                                      $"{PlaylistNrColumnName} = @plnr and " +
                                      $"{SongIdColumnName} = @songid";
                command.Parameters.Add(new SQLiteParameter("@plid", playlist.Id));
                command.Parameters.Add(new SQLiteParameter("@plnr", ySong.PlaylistNr));
                command.Parameters.Add(new SQLiteParameter("@songid", ySong.VideoId));

                var affected = command.ExecuteNonQuery();

                if (affected < 1)
                {
                    _logger.Log("No item deleted when trying to remoce youtube song from db", Category.Warn, Priority.High);
                }
            }
        }
Esempio n. 11
0
 public SongChangedEventArgs(BaseSong currentSong)
 {
     CurrentSong = currentSong;
 }
Esempio n. 12
0
 public OcarinaSong(BaseSong song)
     : base()
 {
     _instrumentType = InstrumentTypes.Ocarina;
 }
Esempio n. 13
0
 public void RemoveSongToQueue(BaseSong song)
 {
     Queue.Songs.Remove(song);
     PlaylistChangedEvent?.Invoke(this, new PlaylistChangedEventArgs());
 }
Esempio n. 14
0
 public bool CanSave(BaseSong song)
 {
     return(song is YoutubeSong);
 }