Ejemplo n.º 1
0
        /// <summary>
        /// Sets the cover image of the given song to the given Picture. Setting it to "null" should result in a deletion.
        /// </summary>
        /// <param name="Song"></param>
        /// <param name="newPicture"></param>
        public static void SetImage(this TagLib.File Song, TagLib.Picture newPicture)
        {
            if (newPicture != null)
            {
                if (Song.Tag.Pictures.FirstOrDefault() != newPicture)
                {
                    TagLib.IPicture[] pic = new TagLib.IPicture[1];

                    pic[0] = newPicture;

                    Song.Tag.Pictures = pic;
                }

                else
                {
                }
            }

            else
            {
                Console.WriteLine("YOOO");

                Song.Tag.Pictures = new TagLib.IPicture[0];
            }
        }
Ejemplo n.º 2
0
        public void DoSetAlbumArt(Song song)
        {
            string songAlbumArt = song.FileLocation;

            TagLib.File f = TagLib.File.Create(songAlbumArt);
            if (f.Tag.Pictures.Length > 0)
            {
                TagLib.IPicture pic = f.Tag.Pictures[0];
                MemoryStream    ms  = new MemoryStream(pic.Data.Data);
                if (ms != null && ms.Length > 4096)
                {
                    ms.Seek(0, SeekOrigin.Begin);
                }
                {
                    currentAlbumArtBMI = new BitmapImage();
                    currentAlbumArtBMI.BeginInit();
                    currentAlbumArtBMI.StreamSource = ms;
                    currentAlbumArtBMI.EndInit();
                }
                ImageBrush imgBrush = new ImageBrush();
                imgBrush.ImageSource      = currentAlbumArtBMI;
                MainWindowGrid.Background = imgBrush;
            }
            else
            {
                ImageBrush imgBrush = new ImageBrush();
                imgBrush.ImageSource      = placeholderImage;
                imgBrush.Opacity          = 0.4;
                MainWindowGrid.Background = imgBrush;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Нажатие на кнопку "Следующий трек"
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnNext_Click(object sender, RoutedEventArgs e)
 {
     if ((playlist.Items.Count != 0) && (playlist.SelectedIndex != -1))
     {
         labelNowPlaying.Content = "Now playing:";
         BassLike.Next();
         slVol.Value            = 100;
         labelLefttime.Content  = TimeSpan.FromSeconds(BassLike.GetPosOfStream(BassLike.Stream)).ToString();
         labelRightTime.Content = TimeSpan.FromSeconds(BassLike.GetTimeOfStream(BassLike.Stream)).ToString();
         slTime.Maximum         = BassLike.GetTimeOfStream(BassLike.Stream);
         slTime.Value           = BassLike.GetPosOfStream(BassLike.Stream);
         try
         {
             if (Vars.Files.Count >= Vars.CurrentTrackNumber + 1)
             {
                 ++playlist.SelectedIndex;
                 labelCurrentPlayingName.Content = Vars.GetFileName((Vars.Files[Vars.CurrentTrackNumber]));
             }
             else if (Vars.CurrentTrackNumber == Vars.Files.Count)
             {
                 labelCurrentPlayingName.Content = Vars.GetFileName(Vars.Files[playlist.SelectedIndex]);
             }
             if (BassLike.isStopped)
             {
                 labelLefttime.Content           = null;
                 labelRightTime.Content          = null;
                 labelCurrentPlayingName.Content = null;
             }
         }
         catch
         {
             labelCurrentPlayingName.Content = null;
         }
         //***************************************************************************************//
         string current = Vars.Files[playlist.SelectedIndex];
         try
         {
             TagLib.File     f       = new TagLib.Mpeg.AudioFile(current);
             TagLib.IPicture pic     = f.Tag.Pictures[0];
             var             mStream = new MemoryStream(pic.Data.Data);
             mStream.Seek(0, SeekOrigin.Begin);
             BitmapImage bm = new BitmapImage();
             bm.BeginInit();
             bm.StreamSource = mStream;
             bm.EndInit();
             System.Windows.Controls.Image cover = new System.Windows.Controls.Image();
             cover.Source = bm;
             image.Source = bm;
         }
         catch
         {
             var uri = new Uri("pack://application:,,,/Resources/nocover.png");
             var img = new BitmapImage(uri);
             image.Source = img;
         }
         //***************************************************************************************//
     }
 }
Ejemplo n.º 4
0
        /*
         * Selecao de arquivo mp3 para a edição
         * Coleta e exibição de informações do arquivo mp3
         */
        private void btnProcurar_Click(object sender, RoutedEventArgs e)
        {
            arq.Filter = "MP3 files(.mp3)|*.mp3";
            if (arq.ShowDialog() == true)
            {
                tocando = false;
                var file = TagLib.File.Create(arq.FileName);
                rota = arq.FileName;
                clear();
                if (!string.IsNullOrEmpty(file.Tag.Title))
                {
                    txtTitulo.Text = file.Tag.Title;
                }
                if (!string.IsNullOrEmpty(file.Tag.Artists[0]))
                {
                    txtArtista.Text = file.Tag.Artists[0];
                }
                try
                {
                    if (!string.IsNullOrEmpty(file.Tag.Genres[0]))
                    {
                        txtGenero.Text = file.Tag.Genres[0];
                    }
                }
                catch {}
                if (!string.IsNullOrEmpty(file.Tag.Album))
                {
                    txtAlbum.Text = file.Tag.Album;
                }
                if (file.Tag.Year != 0 && file.Tag.Year > 0)
                {
                    txtAno.Text = Convert.ToString(file.Tag.Year);
                }

                // imagem do album
                try
                {
                    TagLib.IPicture pic = file.Tag.Pictures[0];
                    MemoryStream    ms  = new MemoryStream(pic.Data.Data);
                    ms.Seek(0, SeekOrigin.Begin);
                    BitmapImage bitmap = new BitmapImage();
                    bitmap.BeginInit();
                    bitmap.StreamSource = ms;
                    bitmap.EndInit();
                    System.Windows.Controls.Image img = new System.Windows.Controls.Image();
                    img.Source     = bitmap;
                    picImge.Source = img.Source;
                    GradientGrid(ms);
                }
                catch { }
                grdPlayer.Visibility = Visibility.Visible;
                stpInfo.Visibility   = Visibility.Visible;
            }
        }
Ejemplo n.º 5
0
        public void refresh(Song s)
        {
            musicTilte.Text  = s.Title;
            musicArtist.Text = s.Artist;
            like.DataContext = s.Id;
            position.Minimum = 0;
            position.Maximum = s.Duration - 1;
            position.Delay   = 1;
            var file = TagLib.File.Create(s.Path);

            TagLib.IPicture pic = file.Tag.Pictures[0];
            MemoryStream    ms  = new MemoryStream(pic.Data.Data);

            ms.Seek(0, SeekOrigin.Begin);
            using (Db db = new Db())
            {
                if (db.Favorites.FirstOrDefault(x => x.UserId == _user.Id && x.SongId == s.Id) == null)
                {
                    like.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 255, 255, 255));
                }
                else
                {
                    like.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(30, 255, 255, 255));
                }
            }
            BitmapImage bitmap = new BitmapImage();

            bitmap.BeginInit();
            bitmap.StreamSource = ms;
            bitmap.EndInit();
            imageSong.Source = bitmap;
            Bitmap btm = new Bitmap(ms);
            var    cl  = getColor(btm);

            main_panel.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, cl.R, cl.G, cl.B));
            dt.Start();
            if (md.isPlay)
            {
                icoPlayStop.Kind = MaterialDesignThemes.Wpf.PackIconKind.Pause;
            }
            else
            {
                icoPlayStop.Kind = MaterialDesignThemes.Wpf.PackIconKind.Play;
            }
        }
Ejemplo n.º 6
0
        public static Bitmap GetCoverImage(this TagLib.File newSong)
        {
            MemoryStream mStream = new MemoryStream();

            TagLib.IPicture firstPicture = newSong.Tag.Pictures.FirstOrDefault();

            if (firstPicture != null)
            {
                byte[] pData = firstPicture.Data.Data;

                mStream.Write(pData, 0, Convert.ToInt32(pData.Length));

                Bitmap CoverImage = new Bitmap(mStream, false);

                mStream.Dispose();

                return(CoverImage);
            }

            return(null);
        }
Ejemplo n.º 7
0
        public string GetEmbedAlbumArt(TagLib.File file, string Folder)
        {
            Console.Write("Searching for embedded artwork... ");
            string path    = new FileInfo(Folder).DirectoryName;
            string prePend = @"data:image/png;base64, ";

            TagLib.IPicture[] pictures = file.Tag.Pictures;
            if (pictures.Any())
            {
                Console.WriteLine("Found!");

                TagLib.IPicture picture = pictures.First();
                Image           image   = Image.Load(picture.Data.Data);
                using (var outputStream = new MemoryStream())
                {
                    image.SaveAsPng(outputStream);
                    return(prePend + Convert.ToBase64String(outputStream.ToArray()));
                }
            }

            return(null);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Нажатие на кнопку "Плей"
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnPlay_Click(object sender, MouseButtonEventArgs e)
 {
     if ((playlist.Items.Count != 0) && (playlist.SelectedIndex != -1))
     {
         dtimer.Start();
         labelNowPlaying.Content = "Now playing:";
         string current = Vars.Files[playlist.SelectedIndex];
         Vars.CurrentTrackNumber = playlist.SelectedIndex;
         BassLike.Play(current, BassLike.Volume);
         labelLefttime.Content           = TimeSpan.FromSeconds(BassLike.GetPosOfStream(BassLike.Stream)).ToString();
         labelRightTime.Content          = TimeSpan.FromSeconds(BassLike.GetTimeOfStream(BassLike.Stream)).ToString();
         slTime.Maximum                  = BassLike.GetTimeOfStream(BassLike.Stream);
         slTime.Value                    = BassLike.GetPosOfStream(BassLike.Stream);
         labelCurrentPlayingName.Content = Vars.GetFileName(current);
         //************************************************************************//
         try
         {
             TagLib.File     f       = new TagLib.Mpeg.AudioFile(current);
             TagLib.IPicture pic     = f.Tag.Pictures[0];
             var             mStream = new MemoryStream(pic.Data.Data);
             mStream.Seek(0, SeekOrigin.Begin);
             BitmapImage bm = new BitmapImage();
             bm.BeginInit();
             bm.StreamSource = mStream;
             bm.EndInit();
             System.Windows.Controls.Image cover = new System.Windows.Controls.Image();
             cover.Source = bm;
             image.Source = bm;
         }
         catch
         {
             var uri = new Uri("pack://application:,,,/Resources/nocover.png");
             var img = new BitmapImage(uri);
             image.Source = img;;
         }
         //***************************************************************************************//
     }
 }
Ejemplo n.º 9
0
    /// <summary>
    /// Writes image data to disk.
    /// </summary>
    /// <remarks>
    /// The image must be stored on disk before the tag
    /// data can be written. Image type always defaults
    /// to <see cref="TagLib.PictureType.FrontCover"/>
    /// </remarks>
    public void Save()
    {
      Trace.WriteLine("Saving " + Name + Extension);

      if(Exists())
      {
        // Write image data to disk
        Image.Save(Path);

        // Create tag-compliant Picture object
        picture = new Picture(Path);
        picture.Type = PictureType.FrontCover;
      }
    }
Ejemplo n.º 10
0
        /// <summary>
        /// Описано задание значений максимальной длины трека, минимально длины трека и значения ползунка
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dtimer_Tick(object sender, EventArgs e)
        {
            if ((playlist.Items.Count != 0) && (playlist.SelectedIndex != -1))
            {
                slTime.Minimum = 0;
                //Получаем значения посекундного измения времени трека при проигывании + вследствие этого движется ползунок
                slTime.Maximum = BassLike.GetTimeOfStream(BassLike.Stream);
                slTime.Value   = BassLike.GetPosOfStream(BassLike.Stream);
                if (BassLike.ToNextTrack() == true)
                {
                    if ((playlist.Items.Count != 0) && (playlist.SelectedIndex != -1))
                    {
                        BassLike.Stop();
                        btnNext_Click(this, new RoutedEventArgs());
                        btnPrev_Click(this, new RoutedEventArgs());
                        btnPlay_Click(this, new RoutedEventArgs());
                        slVol.Value             = 100;
                        labelNowPlaying.Content = "Now playing:";
                        BassLike.Next();
                        labelLefttime.Content  = TimeSpan.FromSeconds(BassLike.GetPosOfStream(BassLike.Stream)).ToString();
                        labelRightTime.Content = TimeSpan.FromSeconds(BassLike.GetTimeOfStream(BassLike.Stream)).ToString();
                        slTime.Maximum         = BassLike.GetTimeOfStream(BassLike.Stream);
                        slTime.Value           = BassLike.GetPosOfStream(BassLike.Stream);
                        try
                        {
                            if (Vars.Files.Count >= Vars.CurrentTrackNumber + 1)
                            {
                                ++playlist.SelectedIndex;
                                labelCurrentPlayingName.Content = Vars.GetFileName((Vars.Files[Vars.CurrentTrackNumber]));
                            }
                            if (Vars.CurrentTrackNumber == Vars.Files.Count)
                            {
                                labelCurrentPlayingName.Content = Vars.GetFileName(Vars.Files[playlist.SelectedIndex]);
                            }
                            if (Vars.CurrentTrackNumber == 0)
                            {
                                playlist.SelectedIndex          = 0;
                                labelCurrentPlayingName.Content = Vars.GetFileName(Vars.Files[0]);
                            }
                            if (BassLike.isStopped)
                            {
                                labelLefttime.Content           = null;
                                labelRightTime.Content          = null;
                                labelCurrentPlayingName.Content = null;
                            }
                        }
                        catch
                        {
                            labelCurrentPlayingName.Content = null;
                        }
                    }


                    //*********************************************************//
                    string current = Vars.Files[playlist.SelectedIndex];
                    Vars.CurrentTrackNumber         = playlist.SelectedIndex;
                    labelCurrentPlayingName.Content = Vars.GetFileName(current);
                    try
                    {
                        TagLib.File     f       = new TagLib.Mpeg.AudioFile(current);
                        TagLib.IPicture pic     = f.Tag.Pictures[0];
                        var             mStream = new MemoryStream(pic.Data.Data);
                        mStream.Seek(0, SeekOrigin.Begin);
                        BitmapImage bm = new BitmapImage();
                        bm.BeginInit();
                        bm.StreamSource = mStream;
                        bm.EndInit();
                        System.Windows.Controls.Image cover = new System.Windows.Controls.Image();
                        cover.Source = bm;
                        image.Source = bm;
                    }
                    catch
                    {
                        var uri = new Uri("pack://application:,,,/Resources/nocover.png");
                        var img = new BitmapImage(uri);
                        image.Source = img;
                    }
                    //***************************************************************************************//
                }
                if (BassLike.endPlaylist)
                {
                    btnStop_Click(this, new RoutedEventArgs());
                    playlist.SelectedIndex = Vars.CurrentTrackNumber = 0;
                    BassLike.endPlaylist   = false;
                }
            }
        }
Ejemplo n.º 11
0
 public static string ReadInfos(bool clearall) //liest alle mp3's aus
 {
     if (clearall)
     {
         dateiname         = null;
         ordner            = null;
         pfad              = null;
         title             = null;
         artist            = null;
         album             = null;
         albumartist       = null;
         track             = null;
         year              = null;
         genre             = null;
         comment           = null;
         amazonID          = null;
         tag               = null;
         tagversion        = null;
         albumcoveradresse = null;
         albumcoverpfad    = null;
         albumcover        = null;
     }
     for (int i = mp3.ordner.Count(); i < Funktionen.anzahl; i++)
     {
         try
         {
             int    index;
             string strin    = mp3.pfad[i];
             string ordne    = "";
             string dateinam = "";
             while (strin.Contains("\\"))
             {
                 index    = strin.IndexOf("\\", 0);
                 ordne    = ordne + strin.Substring(0, index + 1);
                 dateinam = strin.Substring((index + 1));
                 strin    = dateinam;
             }
             mp3.dateiname.Add(dateinam);
             mp3.ordner.Add(ordne);
             TagLib.File f = TagLib.File.Create(mp3.pfad[i]);
             if (f.Tag.Title == null)
             {
                 title.Add(" ");
             }
             else
             {
                 title.Add(f.Tag.Title);
             }
             if (f.Tag.FirstPerformer == null)
             {
                 artist.Add(" ");
             }
             else
             {
                 artist.Add(f.Tag.FirstPerformer);
             }
             if (f.Tag.Album == null)
             {
                 album.Add(" ");
             }
             else
             {
                 album.Add(f.Tag.Album);
             }
             if (f.Tag.FirstAlbumArtist == null)
             {
                 albumartist.Add(" ");
             }
             else
             {
                 albumartist.Add(f.Tag.FirstAlbumArtist);
             }
             if (Convert.ToInt32(f.Tag.Track) == null)
             {
                 track.Add(-1);
             }
             else
             {
                 track.Add(Convert.ToInt32(f.Tag.Track));
             }
             if (Convert.ToInt32(f.Tag.Year) == null)
             {
                 year.Add(-1);
             }
             else
             {
                 year.Add(Convert.ToInt32(f.Tag.Year));
             }
             if (f.Tag.FirstGenre == null)
             {
                 genre.Add(" ");
             }
             else
             {
                 genre.Add(f.Tag.FirstGenre);
             }
             if (f.Tag.Comment == null)
             {
                 comment.Add(" ");
             }
             else
             {
                 comment.Add(f.Tag.Comment);
             }
             if (f.Tag.AmazonId == null)
             {
                 amazonID.Add(" ");
             }
             else
             {
                 amazonID.Add(f.Tag.AmazonId);
             }
             if (f.Tag.TagTypes.ToString() == null)
             {
                 tag.Add(" ");
             }
             else
             {
                 tag.Add(f.Tag.TagTypes.ToString());
             }
             try
             {
                 List <Image>          cover = new List <Image>();
                 System.Drawing.Bitmap flag  = new System.Drawing.Bitmap(10, 10);
                 cover.Add(flag);
                 List <string> albumcoveradr = new List <string>();
                 List <string> albumcoverpfa = new List <string>();
                 albumcoveradr.Add(" ");
                 albumcoverpfa.Add(" ");
                 albumcoveradresse.Add(albumcoveradr);
                 albumcoverpfad.Add(albumcoverpfa);
                 for (int b = 0; i < f.Tag.Pictures.Count(); i++)
                 {
                     TagLib.IPicture pic    = f.Tag.Pictures[b];   //pic contains data for image.
                     MemoryStream    stream = new MemoryStream(pic.Data.Data);
                     cover.Add(Image.FromStream(stream));
                 }
                 mp3.albumcover.Add(cover);
                 f = null;
             }
             catch { return("ReadInfos(): Die Bilder der Datei konnten nicht ausgelesen werden."); }
         }
         catch { return("ReadInfos(): Die Tags der Datei konnten nicht ausgelesen werden."); }
     }
     return("OK");
 }
Ejemplo n.º 12
0
        public async Task <IActionResult> UploadFile(IFormFile uploadFile)
        {
            if (uploadFile != null)
            {
                var user = await _userManager.GetUserAsync(User);

                if (!Directory.Exists(Path.Combine("wwwroot", "Files", $"{user.Id}")))
                {
                    // Create the directory.
                    Directory.CreateDirectory(Path.Combine("wwwroot", "Files", $"{user.Id}"));
                }
                var filePath = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine("wwwroot", "Files", $"{user.Id}"), uploadFile.FileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await uploadFile.CopyToAsync(fileStream);
                }

                var             audioFile = TagLib.File.Create(filePath);
                TagLib.IPicture pic       = null;
                if (audioFile.Tag.Pictures.Length >= 1)
                {
                    pic = audioFile.Tag.Pictures[0];  //pic contains data for image.
                }

                if (pic != null)
                {
                    using (var stream = new MemoryStream(pic.Data.Data))
                    {
                        Audio file = new Audio
                        {
                            Name     = uploadFile.FileName,
                            Path     = Path.Combine("Files", $"{user.Id}", $"{uploadFile.FileName}"),
                            AudioId  = new Guid(),
                            AuthorId = user.Id,
                            Label    = stream.ToArray(),
                            Song     = audioFile.Tag.Album
                        };

                        var userAudio = new UserAudio
                        {
                            User   = user,
                            Audio  = file,
                            Status = Status.Added
                        };

                        _db.UserAudios.Add(userAudio);
                        _db.Audios.Add(file);
                        _db.SaveChanges();
                    }
                }
                else
                {
                    Audio file = new Audio
                    {
                        Name     = uploadFile.FileName,
                        Path     = Path.Combine("Files", $"{user.Id}", $"{uploadFile.FileName}"),
                        AudioId  = new Guid(),
                        AuthorId = user.Id,
                        Label    = null,
                        Song     = audioFile.Tag.Album
                    };

                    var userAudio = new UserAudio
                    {
                        User   = user,
                        Audio  = file,
                        Status = Status.Added
                    };

                    _db.UserAudios.Add(userAudio);
                    _db.Audios.Add(file);
                    _db.SaveChanges();
                }
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 13
0
        private void ChangeAudio(Audio audioContext)
        {
            ms.Source = new Uri(audioContext.DirectoryName + "\\" + audioContext.Name);
            BottomPanel.Visibility  = Visibility.Visible;
            TopPlayGrid.DataContext = audioContext; // обновляем верхнюю панель

            Playing = true;
            ms.Play();

            CurrentIndex = CurrentList.IndexOf(audioContext);

            (PlayButton.Child as Image).Source = LoadImage(@"pack://*****:*****@"pack://application:,,,/Resources/NoImg.jpg", true);
            }
            BottomInfo.DataContext = audioContext;
        }