Esempio n. 1
0
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new TagEditor();

            using (TagLib.File FD = TagLib.File.Create(selectedPath))
            {
                using (Context db = new Context())
                {
                    dialog.Id = SelectAudio();
                    var a = db.Audios.Where(c => c.id == selectedAudioId).ToList <Audio>().FirstOrDefault();
                    dialog.TrackTitle   = a.Title;
                    dialog.Author       = a.Singer;
                    dialog.Album        = a.Album;
                    dialog.Genre        = FD.Tag.FirstGenre;
                    dialog.Year         = FD.Tag.Year.ToString();
                    dialog.counter.Text = a.countPlay.ToString();
                    try
                    {
                        dialog.Image = PlaylistNameDialog.LoadImage(FD.Tag.Pictures[0].Data.Data);
                    }
                    catch
                    {
                        dialog.Image = currentImage;
                    }
                    dialog.Path = selectedPath;
                    FD.Dispose();
                }
            }

            dialog.Show();
            dialog.Closed += Dialog_Closed;
        }
Esempio n. 2
0
 public ICollection <Audio> GetAudiosByPlaylistId()
 {
     using (Context db = new Context())
     {
         var playlists = from Playlist in db.Playlists
                         select new
         {
             id   = Playlist.id,
             list = Playlist.AudioList,
             name = Playlist.Name,
             img  = Playlist.Image
         };
         if (playlists.Where(c => c.id == selectedPlaylistId).FirstOrDefault() != null)
         {
             playlistName.Text    = playlists.Where(c => c.id == selectedPlaylistId).FirstOrDefault().name;
             playlistImage.Source = PlaylistNameDialog.LoadImage(playlists.Where(c => c.id == selectedPlaylistId).FirstOrDefault().img);
             TimeSpan tmp = TimeSpan.Zero;
             foreach (var i in playlists.Where(c => c.id == selectedPlaylistId).FirstOrDefault().list)
             {
                 tmp += i.Duration;
             }
             playlistInfo.Text = tmp.ToString(@"mm\:ss") + " | " + playlists.Where(c => c.id == selectedPlaylistId).FirstOrDefault().list.Count().ToString();
             if (Math.Abs(playlists.Where(c => c.id == selectedPlaylistId).FirstOrDefault().list.Count()) % 10 == 1)
             {
                 playlistInfo.Text += " трек";
             }
             else if
             (Math.Abs(playlists.Where(c => c.id == selectedPlaylistId).FirstOrDefault().list.Count()) % 10 >= 2 && Math.Abs(playlists.Where(c => c.id == selectedPlaylistId).FirstOrDefault().list.Count()) % 10 < 5)
             {
                 playlistInfo.Text += " трекa";
             }
             else if
             (Math.Abs(playlists.Where(c => c.id == selectedPlaylistId).FirstOrDefault().list.Count()) % 10 >= 5)
             {
                 playlistInfo.Text += " треков";
             }
             if (playlists.Where(c => c.id == selectedPlaylistId).FirstOrDefault().list.Count() == 0)
             {
                 playlistInfo.Text += " треков";
             }
             return(playlists.Where(c => c.id == selectedPlaylistId).FirstOrDefault().list);
         }
         else
         {
             ICollection <Audio> audios = null;
             return(audios);
         }
     }
 }
Esempio n. 3
0
        private void EditPlaylistBtn_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new PlaylistNameDialog();

            dialog.ResponseTextBox.Text = playlistName.Text;
            dialog.ImageBox.Source      = playlistImage.Source;
            if (dialog.ShowDialog() == true)
            {
                using (Context db = new Context())
                {
                    var a = db.Playlists.Where(x => x.id == selectedPlaylistId).FirstOrDefault();
                    a.Image = dialog.GetImageByteArray;
                    a.Name  = dialog.ResponseText;
                    db.SaveChanges();
                    UpdateListbox();
                }
            }
        }
Esempio n. 4
0
        private void NewPlaylist_Click_1(object sender, RoutedEventArgs e)
        {
            Playlist playlist;
            string   playlistName;
            var      dialog = new PlaylistNameDialog();

            if (dialog.ShowDialog() == true)
            {
                playlistName = dialog.ResponseText;
                var image = dialog.GetImageByteArray;
                playlist = new Playlist {
                    Name = playlistName, AudioList = null, Image = image
                };                                                                               //(playlistName, audios1, image);
                using (Context db = new Context())
                {
                    db.Playlists.Add(playlist);
                    db.SaveChanges();
                    UpdateListbox();
                }
            }
        }
Esempio n. 5
0
 private void PlayMp3(string path)
 {
     if (isPlaying)
     {
         player.Stop();
         player.Dispose();
     }
     using (var FD = TagLib.File.Create(path))
     {
         if (mainOutputStream != null)
         {
             mainOutputStream.Dispose();
         }
         player = new WaveOutEvent();
         if (!File.Exists(path))
         {
         }
         else
         {
             mainOutputStream = WaveFormatConversionStream.CreatePcmStream(new Mp3FileReader(path)); //new Mp3FileReader(path);
             volumeStream     = new WaveChannel32(mainOutputStream);
             player.Init(volumeStream);
             trackSlider.Maximum = volumeStream.Length;
             string curTimeString = mainOutputStream.TotalTime.ToString("mm\\:ss");
             time2.Text = curTimeString;
             {
                 using (var db = new Context())
                 {
                     var a = db.Audios.Where(a => a.id == selectedAudioId).FirstOrDefault();
                     a.lastPlay  = DateTime.Now;
                     a.countPlay = a.countPlay + 1;
                     db.SaveChanges();
                     trackPerformer.Text = a.Singer;
                     trackName.Text      = a.Title;
                     try
                     {
                         trackCover.Source = PlaylistNameDialog.LoadImage(FD.Tag.Pictures[0].Data.Data);
                     }
                     catch
                     {
                         string        directoryName = Path.GetDirectoryName(path);
                         DirectoryInfo di            = new DirectoryInfo(directoryName);
                         string        firstFileName = di.GetFiles().Select(fi => fi.Name).Where(x => x.Substring(x.Length - 3) == "jpg" || x.Substring(x.Length - 3) == "png" || x.Substring(x.Length - 3) == "jpeg").FirstOrDefault();
                         var           img           = new System.Windows.Media.Imaging.BitmapImage(new Uri(directoryName + @"\" + firstFileName, UriKind.Relative));
                         if (img != null && !string.IsNullOrEmpty(firstFileName))
                         {
                             directoryName     = directoryName + @"\" + firstFileName;
                             currentImage      = new System.Windows.Media.Imaging.BitmapImage(new Uri(@directoryName, UriKind.RelativeOrAbsolute));
                             trackCover.Source = currentImage;
                         }
                         else
                         {
                             currentImage      = new System.Windows.Media.Imaging.BitmapImage(new Uri(@"404.png", UriKind.RelativeOrAbsolute));
                             trackCover.Source = currentImage;
                         }
                     }
                 }
             }
             player.Play();
             isPlaying          = true;
             trackSlider.Value  = 0;
             volumeSlider.Value = volume;
         }
         FD.Dispose();
     }
 }