Пример #1
0
 public static void getMoreInfo(Melodie m, string xmlPath)
 {
     if (File.Exists(xmlPath))
     {
         List <Melodie> ls   = Album.getSongs(xmlPath);
         bool           find = false;
         foreach (Melodie mel in ls)
         {
             if (mel.NumeMelodie == m.NumeMelodie)
             {
                 m.Durata     = mel.Durata;
                 m.Compozitor = mel.Compozitor;
                 m.Interpret  = mel.Interpret;
                 m.Coperta    = mel.Coperta;
                 find         = true;
                 break;
             }
         }
         if (!find)
         {
             m.Interpret  = "unknown";
             m.Compozitor = "unknown";
         }
     }
     else
     {
         m.Interpret  = "unknown";
         m.Compozitor = "unknown";
     }
 }
Пример #2
0
        public static List <Melodie> getSongs(string fileName)
        {
            List <Melodie> lista = new List <Melodie>();
            var            songs = from s in XElement.Load(fileName).Elements("melodie") select s;

            foreach (var song in songs)
            {
                Melodie m = new Melodie();
                m.Durata      = song.Element("durata").Value;
                m.NumeMelodie = song.Element("titlu_melodie").Value;
                m.Compozitor  = song.Element("compozitor").Value;
                m.Interpret   = song.Element("interpret").Value;

                try
                {
                    if (song.Element("coperta").Name == "coperta")
                    {
                        m.Coperta = fileName.Substring(0, fileName.LastIndexOf('\\') + 1) + song.Element("coperta").Value;
                    }
                }
                catch
                {
                    m.Coperta = "No image to display";
                }
                lista.Add(m);
            }
            return(lista);
        }
        private void openFileButton(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Multiselect = true;
            dlg.Filter      = "All Supported File Types(*.mp3,*.wav,*.mpeg,*.wmv,*.avi)|*.mp3;*.wav;*.mpeg;*.wmv;*.avi";
            // Show open file dialog box
            if ((bool)dlg.ShowDialog())
            {
                try
                {
                    foreach (String file in dlg.FileNames)
                    {
                        if (File.Exists(file))
                        {
                            Melodie m = new Melodie();
                            m.URI         = new Uri(file);
                            m.NumeMelodie = (file.Substring(dlg.FileName.LastIndexOf('\\') + 1));
                            m.NumeMelodie = m.NumeMelodie.Substring(0, m.NumeMelodie.LastIndexOf('.'));
                            listView1.Items.Add(m);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message);
                }
            }
        }
 //remove 1
 private void Remove_Click(object sender, RoutedEventArgs e)
 {
     if (listView1.HasItems)
     {
         if (listView1.SelectedItems.Count > 0)
         {
             Melodie aux = (Melodie)listView1.SelectedItem;
             if (aux.NumeMelodie == titluMelodie.Text)
             {
                 Stop_Click(null, null);
             }
             listView1.Items.Remove(listView1.SelectedItem);
         }
         else
         {
             MessageBox.Show("no item selected to be deleted");
         }
     }
     else
     {
         MessageBox.Show("list is empty");
     }
 }
        //play
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Melodie m = (Melodie)listView1.SelectedItem;

            if (m == null && listView1.Items.Count > 0)
            {
                m = (Melodie)listView1.Items[0];
            }
            if (m != null)
            {
                isPlaying             = true;
                PauseButton.IsEnabled = true;
                StopButton.IsEnabled  = true;
                NextButton.IsEnabled  = true;
                PrevButton.IsEnabled  = true;

                if (m.URI != null)
                {
                    try
                    {
                        mediaElement1.Source = m.URI;
                        mediaElement1.Play();
                        timer.Start();
                        titluMelodie.Text = m.NumeMelodie;
                        if (m.Coperta != null)
                        {
                            if (m.Coperta == "No image to display")
                            {
                                Image       i   = new Image();
                                BitmapImage src = new BitmapImage();
                                src.BeginInit();
                                src.UriSource   = new Uri(AppDomain.CurrentDomain.BaseDirectory + @"/img/images.jpg");
                                src.CacheOption = BitmapCacheOption.OnLoad;
                                src.EndInit();
                                i.Source  = src;
                                i.Stretch = Stretch.Uniform;
                            }
                            else
                            {
                                Image       i   = new Image();
                                BitmapImage src = new BitmapImage();
                                src.BeginInit();
                                src.UriSource   = new Uri(m.Coperta);
                                src.CacheOption = BitmapCacheOption.OnLoad;
                                src.EndInit();
                                i.Source  = src;
                                i.Stretch = Stretch.Uniform;
                            }
                        }
                        else
                        {
                            Image       i   = new Image();
                            BitmapImage src = new BitmapImage();
                            src.BeginInit();
                            src.UriSource   = new Uri(AppDomain.CurrentDomain.BaseDirectory + @"/img/images.jpg");
                            src.CacheOption = BitmapCacheOption.OnLoad;
                            src.EndInit();
                            i.Source  = src;
                            i.Stretch = Stretch.Uniform;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Playing error" + ex.StackTrace);
                    }
                }
            }
            else
            {
                MessageBox.Show("No song in list!");
            }
        }