Beispiel #1
0
        public void openfile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog
            {
                Filter = "mp3 files (*.mp3)|*.mp3",
                Title  = "Выберите mp3 файл"
            };

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                isFileOpened      = true;
                file              = new Mp3Lib.Mp3File(openFileDialog1.FileName);
                textBox1.Text     = file.TagHandler.Year;
                textBox2.Text     = file.TagHandler.Album;
                textBox3.Text     = file.TagHandler.Artist;
                textBox4.Text     = file.TagHandler.Song;
                textBox5.Text     = file.TagHandler.Disc;
                textBox6.Text     = file.TagHandler.Genre;
                textBox7.Text     = file.TagHandler.Composer;
                textBox8.Text     = file.TagHandler.Comment;
                pictureBox1.Image = file.TagHandler.Picture;
                button3.Enabled   = true;
                Button1.Enabled   = true;
                MessageBox.Show("Файл открыт успешно!");
            }
            else
            {
                MessageBox.Show("Файл не выбран");
            }
        }
Beispiel #2
0
        private void onClearFileButtonClick(object sender, EventArgs e)
        {
            if (!File.Exists(fileBrowser.InitialDirectory + fileBrowser.FileName))
            {
                openMessageBox(1);
            }
            else
            {
                Mp3Lib.Mp3File file = new Mp3Lib.Mp3File(fileBrowser.InitialDirectory + fileBrowser.FileName);
                file.TagHandler.Artist  = String.Empty;
                file.TagHandler.Album   = String.Empty;
                file.TagHandler.Track   = String.Empty;
                file.TagHandler.Year    = String.Empty;
                file.TagHandler.Title   = String.Empty;
                file.TagHandler.Picture = null;
                file.Update();
                string fullPath = fileBrowser.FileName;
                string fileName = fileBrowser.SafeFileName;
                string path     = fullPath.Replace(fileName, "");


                foreach (string deletingfile in Directory.GetFiles(path, "*.bak").Where(item => item.EndsWith(".bak")))
                {
                    File.Delete(deletingfile);
                }
                openMessageBox(3);
                clearEntries();
            }
        }
Beispiel #3
0
        private void fun_play(bool flag)
        {
            int num;

            if (flag)
            {
                num = 0;
            }
            else
            {
                num = r.Next(0, paths.Count);
            }
            music_path   = paths[num];
            music_number = num;
            PlayFile(music_path);
            Mp3Lib.Mp3File file = new Mp3Lib.Mp3File(music_path);
            if (file.TagHandler.Picture == null)
            {
                pictureBox1.Image = Resources.Music_icon;
            }
            else
            {
                pictureBox1.Image = file.TagHandler.Picture;
            }
            Player.controls.play();
            var tfile = TagLib.File.Create(music_path);

            label1.Text          = tfile.Properties.Duration.ToString(@"mm\:ss");
            Title_Label.Text     = Path.GetFileNameWithoutExtension(music_path);
            progressBar1.Maximum = durations[paths.IndexOf(music_path)];
            ProgressTimer.Start();
            Play_Pause.BackgroundImage = Resources.pause;
            play = true;
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


        private ImageBrush SetCoverMusic()
        {
            try
            {
                Mp3Lib.Mp3File       MP3 = new Mp3Lib.Mp3File(open.FileName);
                System.Drawing.Image S   = MP3.TagHandler.Picture;

                var image        = S;
                var bitmap       = new System.Drawing.Bitmap(image);
                var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                bitmap.Dispose();
                var brush = new ImageBrush(bitmapSource);

                return(brush);
            }

            catch
            {
                string CurrentDirectory = System.IO.Directory.GetCurrentDirectory() + "\\Asset\\Music.png";
                Main.ImageSource = new BitmapImage(new Uri(CurrentDirectory));
                return(Main);
                //B.ImageSource = new BitmapImage(new Uri(@"C:\Program Files (x86)\Harmonymous\HarmsPlayer/Asset/Music.png"));
                // MainImage.Fill = B;
            }
        }
Beispiel #5
0
        private void Add()
        {
            listView1.Items.Clear();
            paths.Clear();
            String dir = Application.StartupPath + @"\Music";

            String[] members = Directory.GetFiles(dir, "*.mp3");
            int      i       = 1;

            foreach (String s in members)
            {
                paths.Add(s);
                Mp3Lib.Mp3File file  = new Mp3Lib.Mp3File(s);
                string         title = file.TagHandler.Title;
                if (title == "")
                {
                    title = Path.GetFileName(s);
                }
                string   artist = file.TagHandler.Artist;
                var      tfile  = TagLib.File.Create(s);
                string   length = tfile.Properties.Duration.ToString(@"hh\:mm\:ss");
                TimeSpan time   = tfile.Properties.Duration;
                durations.Add((int)time.TotalSeconds);
                string   year          = file.TagHandler.Year;
                string   language      = "";
                string   kind_of_mysic = file.TagHandler.Genre;
                string[] row           = { i.ToString(), title, artist, length, year, language, kind_of_mysic };
                var      listViewItem  = new ListViewItem(row);
                listView1.Items.Add(listViewItem);
                i++;
            }
        }
Beispiel #6
0
 private void EditForm_Load(object sender, EventArgs e)
 {
     Mp3Lib.Mp3File file = new Mp3Lib.Mp3File(path);
     textBox1.Text = file.TagHandler.Title;
     textBox2.Text = file.TagHandler.Artist;
     textBox3.Text = file.TagHandler.Year;
     textBox4.Text = file.TagHandler.Genre;
 }
Beispiel #7
0
 public Song(string filePath, WindowsMediaPlayer mediaPlayer)
 {
     SongPath    = filePath;
     file        = new Mp3Lib.Mp3File(SongPath);
     SongName    = file.TagHandler.Title;
     SongPicture = file.TagHandler.Picture;
     SongLyrics  = file.TagHandler.Lyrics;
     SongArtist  = file.TagHandler.Artist;
     SongAlbum   = file.TagHandler.Album;
 }
Beispiel #8
0
 private void listView1_Click(object sender, EventArgs e)
 {
     try
     {
         if (Next.Enabled == false)
         {
             Next.Enabled = true;
             Back.Enabled = true;
         }
         ListViewItem item  = listView1.FocusedItem;
         int          index = int.Parse(item.SubItems[0].Text);
         index--;
         int      counter = 0;
         String   dir     = Application.StartupPath + @"\Music";
         String[] members = Directory.GetFiles(dir, "*.mp3");
         foreach (String s in members)
         {
             if (index == counter)
             {
                 music_path   = s;
                 music_number = index;
                 try
                 {
                     Player.controls.stop();
                 }
                 catch { }
                 PlayFile(music_path);
                 Mp3Lib.Mp3File file = new Mp3Lib.Mp3File(music_path);
                 if (file.TagHandler.Picture == null)
                 {
                     pictureBox1.Image = Resources.Music_icon;
                 }
                 else
                 {
                     pictureBox1.Image = file.TagHandler.Picture;
                 }
                 Play_Pause.BackgroundImage = Resources.pause;
                 Title_Label.Text           = Path.GetFileNameWithoutExtension(music_path);
                 progressBar1.Maximum       = durations[paths.IndexOf(music_path)];
                 ProgressTimer.Start();
                 var tfile = TagLib.File.Create(music_path);
                 label1.Text = tfile.Properties.Duration.ToString(@"mm\:ss");
                 play        = true;
             }
             counter++;
         }
     }
     catch
     {
         refreshLoad();
     }
 }
Beispiel #9
0
        private void UsingCSLib()
        {
            string[] musicFiles = Directory.GetFiles(txtFolderPath.Text, "*.mp3");
            foreach (string musicFile in musicFiles)
            {
                var mp3 = new Mp3Lib.Mp3File(musicFile);
                mp3.TagHandler.Title    = mp3.TagHandler.Title.Replace(txtFind.Text, txtReplace.Text);
                mp3.TagHandler.Album    = mp3.TagHandler.Album.Replace(txtFind.Text, txtReplace.Text);
                mp3.TagHandler.Artist   = mp3.TagHandler.Artist.Replace(txtFind.Text, txtReplace.Text);
                mp3.TagHandler.Composer = mp3.TagHandler.Composer.Replace(txtFind.Text, txtReplace.Text);

                mp3.TagHandler.Comment = mp3.TagHandler.Comment.Replace(txtFind.Text, txtReplace.Text);
                mp3.TagHandler.Genre   = mp3.TagHandler.Genre.Replace(txtFind.Text, txtReplace.Text);
                mp3.TagHandler.Lyrics  = mp3.TagHandler.Lyrics.Replace(txtFind.Text, txtReplace.Text);
                mp3.TagHandler.Song    = mp3.TagHandler.Song.Replace(txtFind.Text, txtReplace.Text);
                foreach (var item in mp3.TagModel)
                {
                }
                mp3.Update();
                //Console.WriteLine(musicFile);
                //Console.WriteLine(mp3.HasTagOfFamily(Id3TagFamily.FileStartTag).ToString());
                //var x = this.GetValidVersion(mp3);
                //var tag = mp3.GetTag(x.Major, x.Minor);
                //Console.WriteLine("Title: {0}", tag.Title.Value);
                //Console.WriteLine("Artist: {0}", tag.Artists.Value);
                //Console.WriteLine("Album: {0}", tag.Album.Value);
                //Mp3Stream xs = new Mp3Stream(new MemoryStream());

                //mp3.WriteTag(tag, x.Major, x.Minor, WriteConflictAction.Replace);

                //foreach (var item in tag.Frames)
                //{
                //    Console.WriteLine(item.ToString());

                //}
                ////Id3Tag tag = mp3.GetTag(Id3TagFamily.FileStartTag);
                ////Console.WriteLine("Title: {0}", tag.Title.Value);
                ////Console.WriteLine("Artist: {0}", tag.Artists.Value);
                ////Console.WriteLine("Album: {0}", tag.Album.Value);
            }

            foreach (var filename in musicFiles)
            {
                //// Find and Replace the file name
                var newname = filename.Replace(txtFind.Text, txtReplace.Text);
                if (filename != newname)
                {
                    File.Move(filename, newname);
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            //file.Save();
            _ms.Close();

            Mp3Lib.Mp3File mp3 = new Mp3Lib.Mp3File(SettingsForm.SongPath);
            mp3.TagHandler.Title  = txtTitle.Text;
            mp3.TagHandler.Album  = txtAlbum.Text;
            mp3.TagHandler.Artist = txtArtist.Text;

            _file.Tag.Title   = txtTitle.Text;
            _file.Tag.Album   = txtAlbum.Text;
            _file.Tag.Artists = new string[] { txtArtist.Text };
            _file.Save();
        }
Beispiel #11
0
 private void Play_Pause_Click(object sender, EventArgs e)
 {
     if (Next.Enabled == false)
     {
         Next.Enabled = true;
         Back.Enabled = true;
     }
     if (play)
     {
         Player.controls.pause();
         ProgressTimer.Stop();
         Play_Pause.BackgroundImage = Resources.play;
         play = false;
     }
     else
     {
         if (music_path == null)
         {
             if (listView1.Items.Count != 0)
             {
                 fun_play(true);
             }
             else
             {
                 MessageBox.Show("There is no music!\n Please select from Explore");
                 Next.Enabled = false;
                 Back.Enabled = false;
             }
         }
         else
         {
             Player.controls.play();
             ProgressTimer.Start();
             Mp3Lib.Mp3File file = new Mp3Lib.Mp3File(music_path);
             if (file.TagHandler.Picture == null)
             {
                 pictureBox1.Image = Resources.Music_icon;
             }
             else
             {
                 pictureBox1.Image = file.TagHandler.Picture;
             }
             Play_Pause.BackgroundImage = Resources.pause;
             Title_Label.Text           = Path.GetFileNameWithoutExtension(music_path);
             play = true;
         }
     }
 }
Beispiel #12
0
 private void Back_Click(object sender, EventArgs e)
 {
     try
     {
         if (Random.ForeColor == Color.Red)
         {
             if (music_number > 0)
             {
                 music_number -= 1;
             }
             else
             {
                 music_number = listView1.Items.Count - 1;
             }
             music_path = paths[music_number];
             Player.controls.stop();
             PlayFile(music_path);
             Mp3Lib.Mp3File file = new Mp3Lib.Mp3File(music_path);
             Title_Label.Text = Path.GetFileNameWithoutExtension(music_path);
             if (file.TagHandler.Picture == null)
             {
                 pictureBox1.Image = Resources.Music_icon;
             }
             else
             {
                 pictureBox1.Image = file.TagHandler.Picture;
             }
             Player.controls.play();
             ProgressTimer.Start();
             Play_Pause.BackgroundImage = Resources.pause;
             var tfile = TagLib.File.Create(music_path);
             label1.Text = tfile.Properties.Duration.ToString(@"mm\:ss");
             play        = true;
         }
         else
         {
             Player.controls.stop();
             fun_play(false);
         }
     }
     catch { }
 }
        //------------------------------------------------------------------------

        private void ChooseFoler()
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                FolderPath = fbd.SelectedPath.ToString();
                filePaths  = Directory.GetFiles(FolderPath, "*.mp3");

                NumOfFiles = filePaths.Length;
                MusicList  = new Mp3Lib.Mp3File[NumOfFiles];
                fileNames  = new string[NumOfFiles];

                for (int i = 0; i < NumOfFiles; i++)
                {
                    MusicList[i] = new Mp3Lib.Mp3File(@filePaths[i]);
                    fileNames[i] = Path.GetFileName(filePaths[i]);      //Zwraca nazwy plików bez ścieżki
                }
            }
        }
Beispiel #14
0
        private void Save()
        {
            foreach (string sng in lstSongs)
            {
                mp3 = new Mp3Lib.Mp3File(sng);
                mp3.TagHandler.Album  = txtAlbum.Text;
                mp3.TagHandler.Artist = txtArtist.Text;

                if (!bDirectory)
                {
                    mp3.TagHandler.Title = txtTitle.Text;
                    mp3.TagHandler.Song  = mp3.TagHandler.Title;
                }

                mp3.TagHandler.Picture = pbImage.Image;
                mp3.Update();
            }

            bModified = false;
        }
        private void MusicList_MouseUp(object sender, MouseButtonEventArgs e)
        {
            ListView V = (ListView)sender;

            StackPanel St     = (StackPanel)V.SelectedItem;
            TextBlock  Num    = (TextBlock)St.Children[0];
            int        Number = Convert.ToInt16(Num.Text);


            Media.Open(new Uri((AddMusic_List[Number - 1])));

            try
            {
                Mp3Lib.Mp3File       MP3 = new Mp3Lib.Mp3File(AddMusic_List[Number - 1]);
                System.Drawing.Image S   = MP3.TagHandler.Picture;

                var image        = S;
                var bitmap       = new System.Drawing.Bitmap(image);
                var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                bitmap.Dispose();
                var brush = new ImageBrush(bitmapSource);

                MainImage.Fill = brush;
            }

            catch
            {
                string CurrentDirectory = System.IO.Directory.GetCurrentDirectory() + "\\Asset\\Music.png";
                Main.ImageSource = new BitmapImage(new Uri(CurrentDirectory));
                MainImage.Fill   = Main;
                //B.ImageSource = new BitmapImage(new Uri(@"C:\Program Files (x86)\Harmonymous\HarmsPlayer/Asset/Music.png"));
                // MainImage.Fill = B;
            }
            if (Material.Kind == MaterialDesignThemes.Wpf.PackIconKind.Pause)
            {
                Material.Kind = MaterialDesignThemes.Wpf.PackIconKind.Play;
            }
            timer.Start();
            PlayPause();
        }
        public ID3EditForm()
        {
            InitializeComponent();
            InitializeStyles();
            SetTitleBar();
            CenterToScreen();

            _ms   = new MemoryStream();
            _file = TagLib.File.Create(SettingsForm.SongPath);
            GetImage();

            try
            {
                Mp3Lib.Mp3File mp3 = new Mp3Lib.Mp3File(SettingsForm.SongPath);
                this.txtTitle.Text  = mp3.TagHandler.Title;
                this.txtAlbum.Text  = mp3.TagHandler.Album;
                this.txtArtist.Text = mp3.TagHandler.Artist;
            }
            catch
            {
            }
        }
Beispiel #17
0
        private void onSaveButtonClick(object sender, EventArgs e)
        {
            if (File.Exists(fileBrowser.InitialDirectory + fileBrowser.FileName))
            {
                Mp3Lib.Mp3File file = new Mp3Lib.Mp3File(fileBrowser.InitialDirectory + fileBrowser.FileName);
                file.TagHandler.Artist = authorTextBox.Text;
                file.TagHandler.Album  = albumTextBox.Text;
                file.TagHandler.Track  = trackTextBox.Text;
                file.TagHandler.Year   = yearTextBox.Text;
                file.TagHandler.Title  = titleTextBox.Text;
                if (isDebug == true)
                {
                    file.TagHandler.Picture = Properties.Resources.dummy;
                }
                else if (File.Exists(pictureBrowser.InitialDirectory + pictureBrowser.FileName))
                {
                    file.TagHandler.Picture = Image.FromFile(pictureBrowser.InitialDirectory + pictureBrowser.FileName);
                }
                file.Update();

                string fullPath = fileBrowser.FileName;
                string fileName = fileBrowser.SafeFileName;
                string path     = fullPath.Replace(fileName, "");


                foreach (string deletingfile in Directory.GetFiles(path, "*.bak").Where(item => item.EndsWith(".bak")))
                {
                    File.Delete(deletingfile);
                }

                openMessageBox(2);
                clearEntries();
            }
            else
            {
                openMessageBox(1);
            }
        }
Beispiel #18
0
        public void ExecuteBulkUpdte()
        {
            string[] musicFiles = Directory.GetFiles(this.FolderName, "*.mp3", (this.IncludeSubFolder? SearchOption.AllDirectories:SearchOption.TopDirectoryOnly));

            foreach (string musicFile in musicFiles)
            {
                var mp3 = new Mp3Lib.Mp3File(musicFile);

                if (string.IsNullOrEmpty(this.Composer) == false)
                {
                    mp3.TagHandler.Composer = this.Composer;
                }

                if (string.IsNullOrEmpty(this.AlbumName) == false)
                {
                    mp3.TagHandler.Album = this.AlbumName;
                }

                if (UpdateFolderNameAsAlbumName)
                {
                    // string Aname = Path.GetDirectoryName(musicFile);
                    mp3.TagHandler.Album = Path.GetFileName(Path.GetDirectoryName(musicFile));
                }

                if (this.Year != null || this.Year > 0)
                {
                    mp3.TagHandler.Year = this.Year.ToString();
                }

                if (string.IsNullOrEmpty(this.Genre) == false)
                {
                    mp3.TagHandler.Genre = this.Genre;
                }

                if (string.IsNullOrEmpty(this.AlbumAritist) == false)
                {
                    var x = mp3.TagModel.Where(c => c.FrameId == "TPE2").FirstOrDefault();
                    if (x == null)
                    {
                        Console.WriteLine("Null");
                        var ft = new Id3Lib.Frames.FrameText("TPE2");
                        ft.Text = this.AlbumAritist;
                        mp3.TagModel.Add(ft);
                    }
                    else
                    {
                        Console.WriteLine("Not Null");
                        ((Id3Lib.Frames.FrameText)x).Text = this.AlbumAritist;
                    }
                }


                if (this.UpdateFSASTitle)
                {
                    string title = System.IO.Path.GetFileNameWithoutExtension(musicFile);
                    mp3.TagHandler.Title = Regex.Replace(title, @"[\d-]", string.Empty).Trim();
                }


                //foreach (var item in mp3.TagModel)
                //{
                //    Console.WriteLine(item.GetType().ToString());

                //    Console.WriteLine(item.FrameId);

                //    Console.WriteLine(((Id3Lib.Frames.FrameText)item).Text);
                //}


                /*   mp3.TagHandler.Title = mp3.TagHandler.Title.Replace(txtFind.Text, txtReplace.Text);
                 * mp3.TagHandler.Album = mp3.TagHandler.Album.Replace(txtFind.Text, txtReplace.Text);
                 * mp3.TagHandler.Artist = mp3.TagHandler.Artist.Replace(txtFind.Text, txtReplace.Text);
                 * mp3.TagHandler.Composer = mp3.TagHandler.Composer.Replace(txtFind.Text, txtReplace.Text);
                 *
                 * mp3.TagHandler.Comment = mp3.TagHandler.Comment.Replace(txtFind.Text, txtReplace.Text);
                 * mp3.TagHandler.Genre = mp3.TagHandler.Genre.Replace(txtFind.Text, txtReplace.Text);
                 * mp3.TagHandler.Lyrics = mp3.TagHandler.Lyrics.Replace(txtFind.Text, txtReplace.Text);
                 * mp3.TagHandler.Song = mp3.TagHandler.Song.Replace(txtFind.Text, txtReplace.Text);
                 * foreach (var item in mp3.TagModel)
                 * {
                 *
                 * }*/


                mp3.Update();

                //Console.WriteLine(musicFile);
                //Console.WriteLine(mp3.HasTagOfFamily(Id3TagFamily.FileStartTag).ToString());
                //var x = this.GetValidVersion(mp3);
                //var tag = mp3.GetTag(x.Major, x.Minor);
                //Console.WriteLine("Title: {0}", tag.Title.Value);
                //Console.WriteLine("Artist: {0}", tag.Artists.Value);
                //Console.WriteLine("Album: {0}", tag.Album.Value);
                //Mp3Stream xs = new Mp3Stream(new MemoryStream());

                //mp3.WriteTag(tag, x.Major, x.Minor, WriteConflictAction.Replace);

                //foreach (var item in tag.Frames)
                //{
                //    Console.WriteLine(item.ToString());

                //}
                ////Id3Tag tag = mp3.GetTag(Id3TagFamily.FileStartTag);
                ////Console.WriteLine("Title: {0}", tag.Title.Value);
                ////Console.WriteLine("Artist: {0}", tag.Artists.Value);
                ////Console.WriteLine("Album: {0}", tag.Album.Value);
            }
        }
Beispiel #19
0
        public static void GetVoiceFromPath(ref Voices voice, string path)
        {
            Image    img      = null;
            FileInfo mp3File  = null;
            Image    waterPic = null;

            try
            {
                mp3File = new FileInfo(path);
                Mp3Lib.Mp3File    mp3file = new Mp3Lib.Mp3File(mp3File);
                Id3Lib.TagHandler taginfo = new Id3Lib.TagHandler(mp3file.TagModel);
                voice.Singer   = taginfo.Artist; // 歌手。
                voice.Album    = taginfo.Album;  // 专辑。
                voice.SongName = taginfo.Title;  // 歌名。
                                                 //log4net.LogHelper.WriteInfo(typeof(Voices), string.Format("{0}:{1}:{2}", taginfo.Artist, taginfo.Album, taginfo.Title));
                                                 //ShellClass sh = new ShellClass();
                                                 //Folder dir = sh.NameSpace(Path.GetDirectoryName(path));
                                                 //FolderItem item = dir.ParseName(Path.GetFileName(path));

                //voice.VoiceTime = string.IsNullOrEmpty(dir.GetDetailsOf(item, 27)) ? 0 : GetTimeSecond(dir.GetDetailsOf(item, 27)); // 获取歌曲时长。
                //voice.Singer = dir.GetDetailsOf(item, 13); // 歌手。
                //voice.Album = dir.GetDetailsOf(item, 14); // 专辑。
                //voice.SongName = dir.GetDetailsOf(item, 21); // 歌名。
                img = taginfo.Picture;
                if (img != null)
                {
                    //string ImgUploadUrl = System.IO.Path.Combine(ConfigurationManager.AppSettings["ImgUploadUrl2"], "mp3", DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString());
                    //string ImageUrl = ConfigurationManager.AppSettings["ImageUrl2"] + "mp3/" + DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString();
                    Guid   guid     = Guid.NewGuid();
                    string fileName = guid.ToString() + ".jpg";
                    //if (!Directory.Exists(ImgUploadUrl))
                    //{
                    //    Directory.CreateDirectory(ImgUploadUrl);
                    //}
                    // string savepath = Path.Combine(ImgUploadUrl, fileName);
                    //if (!File.Exists(savepath))
                    //{
                    //    img.Save(savepath);
                    //}
                    //封面图,传到OSS
                    string aliTempImgKey = string.Empty;
                    string songPic       = AliOSSHelper.GetOssImgKey("jpg", false, out aliTempImgKey);
                    byte[] imgBytes      = Utility.ImgHelper.ImageToBytes(img);
                    bool   putResult     = AliOSSHelper.PutObjectFromByteArray(songPic, imgBytes, 1, ".jpg");
                    voice.SongPic = songPic;// ImageUrl + "/" + fileName; //歌曲图片

                    //带播放水印的图片,传到OSS
                    waterPic = Utility.ImgHelper.GetWaterPic(img);
                    string aliTempImgKeySharePic = string.Empty;
                    string SharePic          = AliOSSHelper.GetOssImgKey("jpg", false, out aliTempImgKeySharePic);
                    byte[] imgBytesSharePic  = Utility.ImgHelper.ImageToBytes(waterPic);
                    bool   putResultSharePic = AliOSSHelper.PutObjectFromByteArray(SharePic, imgBytesSharePic, 1, ".jpg");
                    voice.SharePic = songPic;
                    //Image waterPic = GetWaterPic(img);
                    //  if (!string.IsNullOrEmpty(waterPic))
                    //  {
                    //      voice.SharePic = ImageUrl + "/" + waterPic; //分享图片
                    //  }
                }
                if (mp3File != null)
                {
                    //删除MP3文件
                    mp3File.Delete();
                }
            }
            catch (Exception ex)
            {
                log4net.LogHelper.WriteError(typeof(Mp3Lib.Mp3File), ex);
            }
            finally
            {
                if (img != null)
                {
                    img.Dispose();
                }
                if (waterPic != null)
                {
                    waterPic.Dispose();
                }
            }
        }
Beispiel #20
0
        private void LoadMp3File(string file)
        {
            me_player.Source = new Uri(currentPlayList.Values[file]);
            me_player.Play();

            // ID3 Tag Loader
            try
            {
                Mp3Lib.Mp3File    mp3file = new Mp3Lib.Mp3File(currentPlayList.Values[file]);
                Id3Lib.TagHandler id3Tags = mp3file.TagHandler;
                try
                {
                    lbl_track_artist.Content = "Artist: " + id3Tags.Artist;
                }
                catch
                {
                    lbl_track_artist.Content = "Artist: " + " N/A";
                }
                try
                {
                    lbl_track_title.Content = "Title: " + id3Tags.Title;
                }
                catch
                {
                    lbl_track_title.Content = "Title: " + " N/A";
                }
                try
                {
                    lbl_track_year.Content = "Year: " + id3Tags.Year;
                }
                catch
                {
                    lbl_track_year.Content = "Year: " + " N/A";
                }
                try
                {
                    lbl_track_album.Content = "Album: " + id3Tags.Album;
                }
                catch
                {
                    lbl_track_album.Content = "Album: " + " N/A";
                }
                try
                {
                    lbl_track_no.Content = "Track Number: " + id3Tags.Track;
                }
                catch
                {
                    lbl_track_no.Content = "Track Number: " + " N/A";
                }
                try
                {
                    //// IMAGE lookup is no longer used
                    //
                    //BitmapImage bi = new BitmapImage();
                    //bi.BeginInit();
                    //
                    //MemoryStream ms = new MemoryStream();
                    //id3Tags.Picture.Save(ms, ImageFormat.Bmp);
                    //
                    //ms.Seek(0, SeekOrigin.Begin);
                    //bi.StreamSource = ms;
                    //bi.EndInit();
                    //
                    //img_songImg.Source = bi;
                }
                catch { }
            }
            catch
            {
            }

            isPlaying = true;
        }
Beispiel #21
0
        private void btnAddMusic_Click(object sender, EventArgs e)
        {
            OpenFileDialog oFD = new OpenFileDialog()
            {
                Filter           = "Mp3 File|*.mp3",
                InitialDirectory = @"C:\Users\User\Desktop\Music\Playlist",
                Multiselect      = true,
            };

            if (oFD.ShowDialog() == DialogResult.OK)
            {
                foreach (String file in oFD.FileNames)
                {
                    Mp3Lib.Mp3File mFile = new Mp3Lib.Mp3File(file);
                    _mp3Player = new Mp3Player("0");
                    listitemsPath.Add(file);
                    listitemsName.Add(Path.GetFileName(file));
                    ListViewItem item = new ListViewItem(listitemsName[listitemsPath.Count - 1]);
                    string       artist = null, genre = null;

                    try
                    {
                        artist = mFile.TagHandler.Artist;
                        genre  = mFile.TagHandler.Genre;
                    }
                    catch (Exception)
                    {
                    }

                    if (artist != null)
                    {
                        listitemsArtist.Add(artist);
                    }
                    else
                    {
                        listitemsArtist.Add("Uncnown");
                    }
                    item.SubItems.Add(listitemsArtist[listitemsPath.Count - 1]);

                    if (genre != null)
                    {
                        listitemsGenre.Add(genre);
                        if (!comboBox2.Items.Contains(genre))
                        {
                            comboBox2.Items.Add(genre);
                        }
                    }
                    else
                    {
                        listitemsGenre.Add(" ");
                    }

                    item.SubItems.Add(listitemsGenre[listitemsPath.Count - 1]);

                    listView1.Items.Add(item);
                    if ((listitemsName.Count - 1) % 2 == 1)
                    {
                        listView1.Items[listitemsName.Count - 2].BackColor = Color.FromArgb(242, 242, 242);
                    }
                }
            }
        }
Beispiel #22
0
        private void Init()
        {
            this.Text = "Properties: ";
            foreach (string sng in lstSongs)
            {
                this.Text += Path.GetFileName(sng) + ", ";
                mp3        = new Mp3Lib.Mp3File(sng);

                if (Title == "")
                {
                    Title = mp3.TagHandler.Title;
                }

                if (Album == "")
                {
                    Album = mp3.TagHandler.Album;
                }

                if (Artist == "")
                {
                    Artist = mp3.TagHandler.Artist;
                }

                if (Picture == null)
                {
                    Picture = mp3.TagHandler.Picture;
                }

                if (Album != mp3.TagHandler.Album)
                {
                    if (mp3.TagHandler.Album != "")
                    {
                        bDiferent = true;
                    }
                }

                if (Artist != mp3.TagHandler.Artist)
                {
                    if (mp3.TagHandler.Artist != "")
                    {
                        bDiferent = true;
                    }
                }

                if (bDiferent)
                {
                    Album   = "";
                    Artist  = "";
                    Title   = "";
                    Picture = null;
                    break;
                }
            }

            this.Text = this.Text.Substring(0, this.Text.Length - 2);

            pbImage.Image  = Picture;
            txtAlbum.Text  = Album;
            txtArtist.Text = Artist;
            txtTitle.Text  = Title;

            if (bDirectory)
            {
                lblTitle.Visible = false;
                txtTitle.Visible = false;
                btApply.Enabled  = true;
                bModified        = false;
            }
            else
            {
                btApply.Enabled = false;
                bModified       = false;
            }
        }
        //------------------------------------------------------------------------
        private void ChooseFoler()
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            if (fbd.ShowDialog() == DialogResult.OK)
            {
                FolderPath = fbd.SelectedPath.ToString();
                filePaths = Directory.GetFiles(FolderPath, "*.mp3");

                NumOfFiles = filePaths.Length;
                MusicList = new Mp3Lib.Mp3File[NumOfFiles];
                fileNames = new string[NumOfFiles];

                for (int i = 0; i < NumOfFiles; i++)
                {
                    MusicList[i] = new Mp3Lib.Mp3File(@filePaths[i]);
                    fileNames[i] = Path.GetFileName(filePaths[i]);      //Zwraca nazwy plików bez ścieżki
                }
            }
        }
Beispiel #24
0
        private void btnPlay_Click(object sender, EventArgs e)
        {
            _mp3Player.Dispose();
            Mp3Lib.Mp3File mFile;
            //player = new SoundPlayer();

            string dockName;

            if (listView1.SelectedIndices.Count > 0)
            {
                Mp3Player _mp3Player = new Mp3Player(listitemsPath[listView1.SelectedItems[0].Index]);
                mFile = new Mp3Lib.Mp3File(listitemsPath[listView1.SelectedItems[0].Index]);
                //player.SoundLocation = listitemsPath[listView1.SelectedItems[0].Index];
                dockName = Path.GetFileName(listitemsPath[listView1.SelectedItems[0].Index]);
            }
            else
            {
                Mp3Player _mp3Player = new Mp3Player(listitemsPath[listView1.Items[0].Index]);
                mFile = new Mp3Lib.Mp3File(listitemsPath[listView1.Items[0].Index]);
                //player.SoundLocation = listitemsPath[listView1.Items[0].Index];
                dockName = Path.GetFileName(listitemsPath[listView1.Items[0].Index]);
            }
            string dockTitle   = null;
            Image  dockPicture = null;

            try
            {
                if (dockName != null)
                {
                    lblBSName.Text = dockName;
                }

                dockTitle   = mFile.TagHandler.Artist;
                dockPicture = mFile.TagHandler.Picture;
            }
            catch (Exception)
            {
            }
            if (dockTitle != null)
            {
                label4.Text = dockTitle;
            }
            else
            {
                label4.Text = "Uncnown";
            }

            if (dockPicture != null)
            {
                pictureBox1.Image = new Bitmap(dockPicture);
            }
            else
            {
                pictureBox1.Image = Resource1.Def;
            }

            _mp3Player.SetVolume(trackBar1.Value);
            if (_mp3Player != null)
            {
                _mp3Player.Play();
            }
        }