当前位置: 首页>>代码示例>>C#>>正文


C# TagModel.Add方法代码示例

本文整理汇总了C#中TagModel.Add方法的典型用法代码示例。如果您正苦于以下问题:C# TagModel.Add方法的具体用法?C# TagModel.Add怎么用?C# TagModel.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TagModel的用法示例。


在下文中一共展示了TagModel.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Deserialize


//.........这里部分代码省略.........
                    throw new InvalidTagException("Data is missing after the extended header.");
            }
            else
            {
                rawSize = id3TagSize;
            }

            // Read the frames
            if (rawSize <= 0)
                throw new InvalidTagException("No frames are present in the Tag, there must be at least one present.");

            // Load the tag frames
            uint index = 0;
            var frameHelper = new FrameHelper(frameModel.Header);
            // repeat while there is at least one complete frame available, 10 is the minimum size of a valid frame
            // but what happens when there's only, say, 5 bytes of padding?
            // we need to read a single byte to inspect for padding, then if not, read a whole tag.
            while (index < rawSize)
            {
                byte[] frameId = new byte[4];
                stream.Read(frameId, 0, 1);
                if (frameId[0] == 0)
                {
                    // We reached the padding area between the frames and the end of the tag,
                    // signified by a zero byte where the frame name should be.

                    // we could double check we actually know what's going on
                    // and check the padding goes exactly to the end of the id3 tag
                    // but in fact it doesn't give us any benefit.
                    //
                    // one of the following cases must apply:
                    //
                    // 1) if the id3 tag specifies more bytes than the frames use up,
                    //    and that space is exactly filled with zeros to the first audio frame,
                    //    it complies with the standard and everything is happy.
                    //
                    // 2) if the id3 tag specifies more bytes than the frames use up,
                    //    and that space isn't completely filled with zeros,
                    //    we assume the software that generated the tag
                    //    forgot to zero-fill it properly.
                    //
                    // 3) if the zero padding extends past the start of the id3 tag,
                    //    we assume the audio payload starts with skippable stuff too.
                    //
                    // 4) if the audio payload doesn't start with a valid mpeg audio frame header,
                    //    (VBR headers have valid mpeg audio frame headers)
                    //    we assume there's a tag in a format we don't recognise.
                    //    It still has to comply with the mpeg sync rules,
                    //    so we will have to use that to find the start of the audio.
                    //
                    // in all cases, we read the specified length of the id3 tag
                    // and let the higher-level processing inspect the audio payload
                    // to decide what is audio, what is extra padding,
                    // and what is unrecognised (non-id3) tags.

                    // how much does the tag size say should be left?
                    frameModel.Header.PaddingSize = rawSize - index;

                    //// advance the stream past any zero bytes,
                    //// and verify the real measured size against that specified in the tag
                    //uint observed = SeekEndOfPadding(src) + 1;
                    //if( frameModel.Header.PaddingSize != observed )
                    //    throw new InvalidPaddingException(observed, frameModel.Header.PaddingSize);

                    // advance the stream to the specified end of the tag
                    // this skips any non-zero rubbish in the padding without looking at it.
                    stream.Seek(frameModel.Header.PaddingSize - 1, SeekOrigin.Current);

                    break;
                }
                if (index + 10 > rawSize)
                {
                    // 10 is the minimum size of a valid frame;
                    // we read one already, if less than 9 chars left it's an error.
                    throw new InvalidTagException("Tag is corrupt, must be formed of complete frames.");
                }
                // read another 3 chars
                stream.Read(frameId, 1, 3);
                index += 4; // have read 4 bytes
                //TODO: Validate key valid ranges
                var reader = new BinaryReader(stream);
                uint frameSize = Swap.UInt32(reader.ReadUInt32());
                index += 4; // have read 4 bytes
                // ID3v2.4 now has sync-safe sizes
                if (frameModel.Header.Version == 4)
                    frameSize = Sync.Unsafe(frameSize);

                // The size of the frame can't be larger than the available space
                if (frameSize > rawSize - index)
                    throw new InvalidFrameException("A frame is corrupt, it can't be larger than the available space remaining.");

                ushort flags = Swap.UInt16(reader.ReadUInt16());
                index += 2; // read 2 bytes
                byte[] frameData = new byte[frameSize];
                reader.Read(frameData, 0, (int)frameSize);
                index += frameSize; // read more bytes
                frameModel.Add(frameHelper.Build(UTF8Encoding.UTF8.GetString(frameId, 0, 4), flags, frameData));
            }
            return frameModel;
        }
开发者ID:jasine,项目名称:KinectExplorer,代码行数:101,代码来源:TagManager.cs

示例2: GetFrameModel

        private TagModel GetFrameModel()
        {
            var frameModel = new TagModel();
            var frameText = new FrameText("TIT2");
            frameText.TextCode = TextCode.Ascii;
            frameText.Text = _song;
            frameModel.Add(frameText);

            frameText = new FrameText("TPE1");
            frameText.TextCode = TextCode.Ascii;
            frameText.Text = _artist;
            frameModel.Add(frameText);

            frameText = new FrameText("TALB");
            frameText.TextCode = TextCode.Ascii;
            frameText.Text = _album;
            frameModel.Add(frameText);

            frameText = new FrameText("TYER");
            frameText.TextCode = TextCode.Ascii;
            frameText.Text = _year;
            frameModel.Add(frameText);

            frameText = new FrameText("TRCK");
            frameText.TextCode = TextCode.Ascii;
            frameText.Text = _track.ToString(CultureInfo.InvariantCulture);
            frameModel.Add(frameText);

            var frameFullText = new FrameFullText("COMM");
            frameFullText.TextCode = TextCode.Ascii;
            frameFullText.Language = "eng";
            frameFullText.Description = "";
            frameFullText.Text = _comment;
            frameModel.Add(frameFullText);

            if (_genre >= 0 && _genre < _genres.Length)
            {
                // from suggestion in http://sourceforge.net/tracker2/?func=detail&aid=920249&group_id=89188&atid=589317
                frameText = new FrameText("TCON");
                frameText.TextCode = TextCode.Ascii;
                frameText.Text = _genres[_genre];
                frameModel.Add(frameText);
            }

            //TODO: Fix this code!!!!!!!!
            frameModel.Header.TagSize = 0;    //TODO: Invalid size, not filled in until write
            frameModel.Header.Version = 3;    // ID3v2.[3].[0]
            frameModel.Header.Revision = 0;
            frameModel.Header.Unsync = false;
            frameModel.Header.Experimental = false;
            frameModel.Header.Footer = false;
            frameModel.Header.ExtendedHeader = false;

            return frameModel;
        }
开发者ID:iWay7,项目名称:MP3TagEditor,代码行数:55,代码来源:ID3v1.cs


注:本文中的TagModel.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。