Esempio n. 1
0
        private void searchMusic()
        {
            String keyword = KeywordTextBox.Text;
            String key     = Preference.youtebeApiKey;
            String part    = "id, snippet";
            String url     = BuildQueryaUrl(part, key, keyword);

            String  searchResult = HttpRequest.OpenUrl(url);
            JObject json         = JObject.Parse(searchResult);
            JArray  youtubeItems = JArray.Parse(json["items"].ToString());
            List <YoutubeSearchItem> youtubeSearchItems = new List <YoutubeSearchItem>();

            foreach (JObject youtubeItem in youtubeItems)
            {
                try
                {
                    String            videoId           = youtubeItem["id"]["videoId"].ToString();
                    String            title             = youtubeItem["snippet"]["title"].ToString();
                    String            channel           = youtubeItem["snippet"]["channelTitle"].ToString();
                    String            thumbnail         = youtubeItem["snippet"]["thumbnails"]["high"]["url"].ToString();
                    YoutubeSearchItem youtubeSearchItem = new YoutubeSearchItem(videoId, title, channel, thumbnail);
                    youtubeSearchItems.Add(youtubeSearchItem);
                } catch (Exception)
                {
                    continue;
                }
            }
            youtubeSearchListBox.ItemsSource = youtubeSearchItems;
        }
Esempio n. 2
0
 private void LoadState()
 {
     if (Preference.isStateFileExist())
     {
         String Text = File.ReadAllText(Preference.stateFilePath);
         if (Text.Length != 0)
         {
             try
             {
                 JObject json = JObject.Parse(Text);
                 LoopState   = (LoopStates)int.Parse(json["loopState"].ToString());
                 RandomState = (RandomStates)int.Parse(json["randomState"].ToString());
                 int index = int.Parse(json["index"].ToString());
                 volume = float.Parse(json["volume"].ToString());
                 YoutubeSearchItem music = PlayList.List[index];
                 currentMusic           = music;
                 PlayerThumbnail.Source = new BitmapImage(new Uri(currentMusic.Thumbnail));
                 titleTextBlock.Text    = currentMusic.Title;
                 PlayList.randomSwap(currentMusic);
                 state = States.Stopped;
             }
             catch (Exception ex)
             {
                 Debug.WriteLine(ex);
             }
         }
     }
     else
     {
         loopState   = LoopStates.NotLoop;
         randomState = RandomStates.UnRandom;
     }
 }
Esempio n. 3
0
 public static void removeItem(YoutubeSearchItem item)
 {
     lock (_syncLock)
     {
         list.Remove(item);
         Shuffle();
     }
 }
Esempio n. 4
0
        public static void randomSwap(YoutubeSearchItem item)
        {
            Shuffle();
            int index = randomList.IndexOf(item);
            YoutubeSearchItem temp = randomList[index];

            randomList[index] = randomList[0];
            randomList[0]     = temp;
        }
Esempio n. 5
0
 public static void addItem(YoutubeSearchItem item)
 {
     lock (_syncLock)
     {
         Shuffle();
         list.Add(item);
         randomList.Add(item);
     }
 }
Esempio n. 6
0
 private void PlayListDoubleClick(object sender, MouseButtonEventArgs e)
 {
     try {
         ListBoxItem       item         = ItemsControl.ContainerFromElement(sender as ListBox, e.OriginalSource as DependencyObject) as ListBoxItem;
         YoutubeSearchItem currentMusic = item.Content as YoutubeSearchItem;
         DataEventArgs     args         = new DataEventArgs();
         args.Data1 = currentMusic;
         playListDoubleClick?.Invoke(this, args);
         PlayList.randomSwap(currentMusic);
     } catch (Exception ex)
     {
         Debug.WriteLine(ex);
     }
 }
Esempio n. 7
0
 private static void Shuffle(int time = 1)
 {
     for (int t = 0; t < time; t++)
     {
         for (int i = 0; i < randomList.Count; i++)
         {
             Random            random = new Random();
             int               index  = random.Next(0, randomList.Count);
             YoutubeSearchItem temp   = randomList[i];
             randomList[i]     = randomList[index];
             randomList[index] = temp;
         }
     }
 }
Esempio n. 8
0
        private void TrashImageMouseDown(object sender, MouseButtonEventArgs e)
        {
            Image             image = sender as Image;
            YoutubeSearchItem item  = image.DataContext as YoutubeSearchItem;

            if (Player.currentMusic != item)
            {
                PlayList.List.Remove(item);
                PlayList.Save();
            }
            else
            {
                MessageBox.Show("현재 재생중인 곡입니다.");
            }
        }
Esempio n. 9
0
        private void YoutubeItemDoubleClick(object sender, MouseButtonEventArgs e)
        {
            ListBoxItem item = ItemsControl.ContainerFromElement(sender as ListBox, e.OriginalSource as DependencyObject) as ListBoxItem;

            try
            {
                YoutubeSearchItem selectedItem = item.Content as YoutubeSearchItem;
                if (item != null)
                {
                    PlayList.addItem(selectedItem);
                    PlayList.Save();
                    musicListImageClick?.Invoke(sender, EventArgs.Empty);
                }
            }
            catch (Exception)
            {
            }
        }