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


C# File.Seek方法代码示例

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


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

示例1: ReadSv8Properties

        private void ReadSv8Properties(File file)
        {
            bool foundSH = false;

            while (!foundSH)
            {
                ByteVector packetType = file.ReadBlock(2);

                uint packetSizeLength = 0;
                bool eof = false;

                ulong packetSize = ReadSize(file, ref packetSizeLength, ref eof);
                if (eof)
                {
                    break;
                }

                ulong payloadSize = packetSize - 2 - packetSizeLength;
                ByteVector data = file.ReadBlock((int)payloadSize);

                if (packetType == "SH")
                {
                    foundSH = true;

                    if (payloadSize <= 5)
                    {
                        break;
                    }

                    int pos = 4;
                    version = data[pos];
                    pos += 1;
                    frames = (uint)ReadSize(data, ref pos);
                    if (pos > (uint)payloadSize - 3)
                    {
                        break;
                    }

                    ulong beginSilence = ReadSize(data, ref pos);
                    if (pos > (uint)payloadSize - 2)
                    {
                        break;
                    }

                    ushort flags = data.Mid(pos, 1).ToUShort(true);

                    sample_rate = sftable[(flags >> 13) & 0x07];
                    channels = ((flags >> 4) & 0x0F) + 1;

                    framecount = frames - beginSilence;
                }
                else if (packetType == "SE")
                {
                    break;
                }
                else
                {
                    file.Seek((int)payloadSize, SeekOrigin.Current);
                }
            }
        }
开发者ID:MediaPortal,项目名称:MPTagThat,代码行数:61,代码来源:StreamHeader.cs

示例2: Tag

		/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="Tag" /> by reading the contents from a specified
		///    position in a specified file.
		/// </summary>
		/// <param name="file">
		///    A <see cref="File" /> object containing the file from
		///    which the contents of the new instance is to be read.
		/// </param>
		/// <param name="position">
		///    A <see cref="long" /> value specify at what position to
		///    read the tag.
		/// </param>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="file" /> is <see langword="null" />.
		/// </exception>
		/// <exception cref="ArgumentOutOfRangeException">
		///    <paramref name="position" /> is less than zero or greater
		///    than the size of the file.
		/// </exception>
		/// <exception cref="CorruptFileException">
		///    The file does not contain <see cref="FileIdentifier" />
		///    at the given position.
		/// </exception>
		public Tag (File file, long position)
		{
			if (file == null)
				throw new ArgumentNullException ("file");
			
			file.Mode = TagLib.File.AccessMode.Read;
			
			if (position < 0 ||
				position > file.Length - Size)
				throw new ArgumentOutOfRangeException (
					"position");
			
			file.Seek (position);
			
			// read the tag -- always 128 bytes
			
			ByteVector data = file.ReadBlock ((int) Size);
			
			// some initial sanity checking
			
			if (!data.StartsWith (FileIdentifier))
				throw new CorruptFileException (
					"ID3v1 data does not start with identifier.");
			
			Parse (data);
		}
开发者ID:JohnThomson,项目名称:taglib-sharp,代码行数:50,代码来源:Tag.cs

示例3: StreamHeader

        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="StreamHeader" /> for a specified header block and
        ///    stream length.
        /// </summary>
        /// <param name="data">
        ///    A <see cref="ByteVector" /> object containing the stream
        ///    header data.
        /// </param>
        /// <param name="streamLength">
        ///    A <see cref="long" /> value containing the length of the
        ///    MusePAck stream in bytes.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="data" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="CorruptFileException">
        ///    <paramref name="data" /> does not begin with <see
        ///    cref="FileIdentifierSv7" />  or with <see 
        ///    cref="FileIdentifierSv8" /> or is less than 
        ///    <see cref="Size" /> bytes long.
        /// </exception>
        public StreamHeader(File file, long streamLength)
        {
            if (file == null)
                throw new ArgumentNullException ("file");

            // Assign default values, to be able to call methods
            // in the constructor
            stream_length = streamLength;
            version = 7;
            header_data = 0;
            frames = 0;
            sample_rate = 0;
            channels = 2;
            framecount = 0;

            file.Seek(0);
            ByteVector magic = file.ReadBlock(4);
            if (magic.StartsWith(FileIdentifierSv7))
                // SV7 Format has a fixed Header size
                ReadSv7Properties(magic + file.ReadBlock((int)SizeSV7 - 4));
            else if (magic.StartsWith(FileIdentifierSv8))
                // for SV8 the properties need to be read from
                // packet information inside the file
                ReadSv8Properties(file);
            else
                throw new CorruptFileException(
                        "Data does not begin with identifier.");
        }
开发者ID:MediaPortal,项目名称:MPTagThat,代码行数:50,代码来源:StreamHeader.cs


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