Beispiel #1
0
        private async void Albums_AlbumsListBox_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            if (!TaskIsRunning)
            {
                Albums_SongsListBox.BeginUpdate();
                var SelectedItem = (string)Albums_AlbumsListBox.SelectedItem;
                await Task.Run(() =>
                {
                    Albums_SongsListBox.Invoke(new Action(() => Albums_SongsListBox.Items.Clear()));
                    AlbumSongLibrary.Clear();
                    List <string> songs = DatabaseHandler.ReadSongs();
                    foreach (string x in songs)
                    {
                        ATL.Track theTrack = new ATL.Track(x);

                        if (theTrack.Album == SelectedItem)
                        {
                            Albums_SongsListBox.Invoke(new Action(() => Albums_SongsListBox.Items.Add($"{theTrack.Artist} - {theTrack.Title}")));
                            AlbumSongLibrary.Add(x);
                        }
                    }
                });

                Albums_SongsListBox.EndUpdate();
            }
            else
            {
                Notification notification = new Notification("Hold up!", "Can't do this now because a background\ntask is working with the library.", 2500);
                notification.Show();
            }
        }
Beispiel #2
0
        private async void searchBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (SearchTasksRunning == 0) // Prevent multiple of these tasks happening at once (else this will use massive amounts of resources)
            {
                SearchTasksRunning++;
                Search_SongsListBox.BeginUpdate();
                await Task.Run(() =>
                {
                    Search_SongsListBox.Invoke(new Action(() => Search_SongsListBox.Items.Clear()));
                    SearchSongLibrary.Clear();
                    List <string> songs = DatabaseHandler.ReadSongs();
                    foreach (string x in songs)
                    {
                        //if (SearchTasksRunning > 1) break;
                        ATL.Track theTrack = new ATL.Track(x);
                        if (theTrack.Artist.Contains(searchBox.Text) || theTrack.Title.Contains(searchBox.Text))
                        {
                            Search_SongsListBox.Invoke(new Action(() => Search_SongsListBox.Items.Add($"{theTrack.Artist} - {theTrack.Title}")));
                            SearchSongLibrary.Add(x);
                        }
                    }
                });

                Search_SongsListBox.EndUpdate();
                SearchTasksRunning--;
            }
        }
Beispiel #3
0
 private void songChangedHandler(object sender, EventArgs e)
 {
     progressTimer.Enabled = true;
     ATL.Track metadata = new ATL.Track(Player.filePath);
     titleLabel.Text = $"{metadata.Artist} - {metadata.Title}";
     Text            = $"{metadata.Artist} - {metadata.Title} | FRESHMusicPlayer";
     getAlbumArt();
     ProgressBar.Maximum = (int)Player.audioFile.TotalTime.TotalSeconds;
     if (Properties.Settings.Default.General_DiscordIntegration)
     {
         Player.UpdateRPC("play", metadata.Artist, metadata.Title);
     }
 }
Beispiel #4
0
        private OperationResult <AudioMetaData> MetaDataForFileFromATL(string fileName)
        {
            var sw = new Stopwatch();

            sw.Start();
            AudioMetaData result    = new AudioMetaData();
            var           isSuccess = false;

            try
            {
                result.Filename = fileName;
                var theTrack = new ATL.Track(fileName);
                result.Release         = theTrack.Album;
                result.Artist          = theTrack.AlbumArtist ?? theTrack.Artist;
                result.ArtistRaw       = theTrack.AlbumArtist ?? theTrack.Artist;
                result.Genres          = theTrack.Genre?.Split(new char[] { ',', '\\' });
                result.TrackArtist     = theTrack.OriginalArtist ?? theTrack.Artist ?? theTrack.AlbumArtist;
                result.TrackArtistRaw  = theTrack.OriginalArtist;
                result.AudioBitrate    = (int?)theTrack.Bitrate;
                result.AudioSampleRate = (int)theTrack.Bitrate;
                result.Disk            = theTrack.DiscNumber;
                if (theTrack.AdditionalFields.ContainsKey("TSST"))
                {
                    result.DiskSubTitle = theTrack.AdditionalFields["TSST"];
                }
                result.Images = theTrack.EmbeddedPictures?.Select(x => new AudioMetaDataImage
                {
                    Data        = x.PictureData,
                    Description = x.Description,
                    MimeType    = "image/jpg",
                    Type        = x.PicType == PictureInfo.PIC_TYPE.Front || x.PicType == PictureInfo.PIC_TYPE.Generic ? AudioMetaDataImageType.FrontCover : AudioMetaDataImageType.Other
                }).ToArray();
                result.Time        = theTrack.DurationMs > 0 ? ((decimal?)theTrack.DurationMs).ToTimeSpan() : null;
                result.Title       = theTrack.Title.ToTitleCase(false);
                result.TrackNumber = (short)theTrack.TrackNumber;
                result.Year        = theTrack.Year;
                isSuccess          = result.IsValid;
            }
            catch (Exception ex)
            {
                this.Logger.LogError(ex, "MetaDataForFileFromTagLib Filename [" + fileName + "] Error [" + ex.Serialize() + "]");
            }
            sw.Stop();
            return(new OperationResult <AudioMetaData>
            {
                IsSuccess = isSuccess,
                OperationTime = sw.ElapsedMilliseconds,
                Data = result
            });
        }
Beispiel #5
0
        private void getAlbumArt()
        {
            ATL.Track theTrack = new ATL.Track(Player.filePath);
            IList <ATL.PictureInfo> embeddedPictures = theTrack.EmbeddedPictures;

            if (embeddedPictures.Count != 0)
            {
                albumArt          = Image.FromStream(new MemoryStream(embeddedPictures[0].PictureData));
                albumartBox.Image = albumArt;
            }
            else
            {
                albumArt          = null;
                albumartBox.Image = albumArt;
            }
        }
Beispiel #6
0
    private static void OnAlbumArtPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var image = d as Image;

        if (d == null)
        {
            return;
        }

        if (e.NewValue == null)
        {
            BindingOperations.ClearBinding(d, Image.SourceProperty);
            return;
        }

        if (e.NewValue is TrackInfo trackInfo)
        {
            if (File.Exists(trackInfo.Path))
            {
                try
                {
                    var track        = new ATL.Track(trackInfo.Path);
                    var albumArtData = track.EmbeddedPictures.FirstOrDefault();

                    if (albumArtData?.PictureData?.Length > 0)
                    {
                        var imageSource = new BitmapImage();
                        imageSource.BeginInit();
                        imageSource.CacheOption  = BitmapCacheOption.None;
                        imageSource.StreamSource = new MemoryStream(ImageUtil.ShrinkImageData(albumArtData.PictureData, 128));
                        imageSource.EndInit();
                        imageSource.Freeze();

                        image.SetValue(Image.SourceProperty, imageSource);

                        return;
                    }
                }
                catch { /* pass */ }
            }
        }

        d.SetValue(Image.SourceProperty, ImageUtil.GetMissingMusicImage());
    }
Beispiel #7
0
        public MainWindow()
        {
            InitializeComponent();

            // Lecture liste morceaux enregistrer

            listeMorceaux = new List <Tracks>();
            sauvegarde    = new enregFichier();

            if (sauvegarde.TestExistenceFichier() == true)
            {
                listeMorceaux = sauvegarde.recuperationListe();
                string[] infoLigne = listeMorceaux.ElementAt(0).Getinfos();
                monLecteur.Source = new Uri(infoLigne[3]);

                numeroPlayListe = 0;
                chemin          = infoLigne[3];
                string[] decoupe = chemin.Split('/');

                theTrack           = new ATL.Track(chemin);
                lblArtiste.Content = theTrack.Artist;
                lblChemin.Content  = theTrack.Title;
                lblAlbum.Content   = theTrack.Album;
                if (theTrack.Year == 0)
                {
                    lblAnnee.Content = "";
                }
                else
                {
                    lblAnnee.Content = Convert.ToString(theTrack.Year);
                }

                lblGenre.Content = theTrack.Genre;
                if (theTrack.TrackTotal == 0)
                {
                    lblpiste.Content = theTrack.TrackNumber;
                }
                else
                {
                    lblpiste.Content = theTrack.TrackNumber + " / " + theTrack.TrackTotal;
                }
                lblCompositeur.Content = theTrack.Composer;
                int heureDuree  = theTrack.Duration / 3600;
                int minuteDuree = (theTrack.Duration - (heureDuree * 3600)) / 60;
                int secDuree    = theTrack.Duration - (heureDuree * 3600) - (minuteDuree * 60);
                if (heureDuree == 0)
                {
                    lblDuree.Content = minuteDuree + " m " + secDuree + " s";
                }
                else
                {
                    lblDuree.Content = heureDuree + " h " + minuteDuree + " m " + secDuree + " s";
                }
                lblComment.Content = theTrack.Comment;
            }

            DispatcherTimer timer = new DispatcherTimer();

            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick    += timer_Tick;
            timer.Start();
        }