コード例 #1
0
ファイル: OneDrive.cs プロジェクト: grieserl/OnePlayer
        public async Task <string> saveArtwork(TagLib.Tag tag, int id)
        {
            IPicture   picture = tag.Pictures[0];
            ByteVector vector  = picture.Data;

            Byte[] bytes     = vector.ToArray();
            string extension = MimeTypesMap.GetExtension(picture.MimeType);

            System.IO.Directory.CreateDirectory(System.IO.Path.Combine(App.LocalStoragePath, "AlbumArt"));
            var filename = System.IO.Path.Combine(App.LocalStoragePath, "AlbumArt", id.ToString() + "." + extension);

            System.IO.File.WriteAllBytes(filename, bytes);
            return(id.ToString() + "." + extension);
        }
コード例 #2
0
        public static Bitmap GetImageFromByteArray(ByteVector objByteVector)
        {
            int width  = 320;
            int height = 240;

            // Convert the Malmo ByteVector to a byteArray
            byte[] byteArray = objByteVector.ToArray();

            // Create a Bitmap
            Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
            int    pos = 0;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    bmp.SetPixel(x, y, Color.FromArgb(byteArray[pos], byteArray[pos + 1], byteArray[pos + 2]));
                    pos += 3;
                }
            }

            // Return the Bitmap
            return(bmp);
        }
コード例 #3
0
 // Constructor: byteVector v2 = new byteVector( v1 );
 public ByteVector(ByteVector that) : base()
 {
     this.CopyFromArray(that.ToArray()); return;
 }
コード例 #4
0
        //Additional info here http://gabriel.mp3-tech.org/mp3infotag.html
        //https://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header

        /// <summary>See if the mp3 file is encoded using VBR. Not sure what to do with ABR...
        /// </summary>
        private bool IsVBR()
        {
            bool bVBR = false;

            if (currentFile.MimeType != "taglib/mp3")
            {
                return(false);
            }

            foreach (ICodec codec in currentFile.Properties.Codecs)
            {
                TagLib.Mpeg.AudioHeader header = (TagLib.Mpeg.AudioHeader)codec;
                //                if (header == null)
                //                    return;

                if (header.XingHeader.Present)
                {
                    currentFile.Mode = TagLib.File.AccessMode.Read;
                    long XingHeader = currentFile.Find(TagLib.Mpeg.XingHeader.FileIdentifier);
                    long Offset     = TagLib.Mpeg.XingHeader.XingHeaderOffset(header.Version, header.ChannelMode);
                    TagLib.Mpeg.XingHeader xing_header = TagLib.Mpeg.XingHeader.Unknown;
                    currentFile.Seek(XingHeader);// + Offset);
                    ByteVector xing_data = currentFile.ReadBlock(16);
                    if (xing_data.Count == 16 && xing_data.StartsWith(
                            TagLib.Mpeg.XingHeader.FileIdentifier))
                    {
                        xing_header = new TagLib.Mpeg.XingHeader(xing_data);
                    }

                    int  Flags          = BitConverter.ToInt32(xing_data.Take(8).ToArray().Reverse().ToArray(), 0);
                    bool FramesPresent  = (Flags & 0x0001) > 0;
                    bool BytesPresent   = (Flags & 0x0002) > 0;
                    bool TOCPresent     = (Flags & 0x0004) > 0;
                    bool QualityPresent = (Flags & 0x0008) > 0;
                    long LameHeader     = currentFile.Find(LAME_Identifier);

                    if (QualityPresent)
                    {
                        //Header offset + 8 (XING + flags) + Frames, Bytes and TOC if available
                        currentFile.Seek(XingHeader + 8 + 4 * (FramesPresent ? 1 : 0) + 4 * (BytesPresent ? 1 : 0) + 100 * (TOCPresent ? 1 : 0));
                        ByteVector Quality_data = currentFile.ReadBlock(4);
                        int        VBRQuality   = BitConverter.ToInt32(Quality_data.ToArray().Reverse().ToArray(), 0);
                        bVBR = true;
                    }
                    currentFile.Mode = TagLib.File.AccessMode.Closed;

                    //                    if (xing_header.Present)
                    //                        return false;
                    //                    var vector = new TagLib.ByteVector();
                    //                    TagLib.ByteVector xing = header.;
                    /* CODE HERE */

                    /*                    TagLib.File ref(fileName);
                     *                  TagLib.Mpeg.File *file = dynamic_cast<TagLib.Mpeg.File *>(ref file());
                     *
                     *                  if(!file)
                     *                      return;
                     *
                     *                  TagLib.Mpeg.Properties *properties = file->audioProperties();
                     *                  const TagLib::MPEG::XingHeader *xingHeader = properties->xingHeader();
                     *
                     *                  if(!xingHeader)
                     *                      return;
                     */
                }

                if (header.VBRIHeader.Present)
                {
                    /* CODE HERE */
                }
            }
            return(bVBR);
        }