Ejemplo n.º 1
0
        private void buttonID3_Click(object sender, RoutedEventArgs e)
        {
            string mimeType = "";

            byte[] albumCoverArt = new byte[0];
            string path          = textBoxId3AlbumCoverArtPath.Text;

            if (path != null && 0 < path.Length)
            {
                using (var br = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))) {
                    albumCoverArt = br.ReadBytes((int)br.BaseStream.Length);
                }

                switch (System.IO.Path.GetExtension(path).ToLower())
                {
                case ".png":
                    mimeType = "image/png";
                    break;

                case ".jpg":
                case ".jpeg":
                    mimeType = "image/jpeg";
                    break;

                default:
                    MessageBox.Show(
                        string.Format("Error: unrecognized image format. png or jpeg required: {0}", path));
                    return;
                }
            }

            var p = new ID3ChunkParams();

            p.Title                 = textBoxId3Title.Text;
            p.Album                 = textBoxId3Album.Text;
            p.Artists               = textBoxId3Artists.Text;
            p.AlbumCoverArt         = albumCoverArt;
            p.AlbumCoverArtMimeType = mimeType;

            if ((p.Title == null || p.Title.Length == 0) &&
                (p.Album == null || p.Album.Length == 0) &&
                (p.Artists == null || p.Artists.Length == 0))
            {
                MessageBox.Show("Error: ID3 title or album or artist name is required to add ID3 chunk");
                return;
            }

            WavChunk = p;

            DialogResult = true;
            Close();
        }
Ejemplo n.º 2
0
        private void buttonID3_Click(object sender, RoutedEventArgs e)
        {
            string mimeType = "";
            byte[] albumCoverArt = new byte[0];
            string path = textBoxId3AlbumCoverArtPath.Text;
            if (path != null && 0 < path.Length) {
                using (var br = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))) {
                    albumCoverArt = br.ReadBytes((int)br.BaseStream.Length);
                }

                switch (System.IO.Path.GetExtension(path).ToLower()) {
                case ".png":
                    mimeType = "image/png";
                    break;
                case ".jpg":
                case ".jpeg":
                    mimeType = "image/jpeg";
                    break;
                default:
                    MessageBox.Show(
                        string.Format("Error: unrecognized image format. png or jpeg required: {0}", path));
                    return;
                }
            }

            var p = new ID3ChunkParams();
            p.Title = textBoxId3Title.Text;
            p.Album = textBoxId3Album.Text;
            p.Artists = textBoxId3Artists.Text;
            p.AlbumCoverArt = albumCoverArt;
            p.AlbumCoverArtMimeType = mimeType;

            if ((p.Title == null || p.Title.Length == 0) &&
                    (p.Album == null || p.Album.Length == 0) &&
                    (p.Artists == null || p.Artists.Length == 0)) {
                MessageBox.Show("Error: ID3 title or album or artist name is required to add ID3 chunk");
                return;
            }

            WavChunk = p;

            DialogResult = true;
            Close();
        }