Click here to Skip to main content
15,886,110 members
Articles / Programming Languages / C#

Repair RealMedia Files

Rate me:
Please Sign up or sign in to vote.
4.50/5 (13 votes)
3 Jan 2007CPOL2 min read 71K   1.7K   32  
Check and fix errors, rebuild index chunks, cut real media files.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace QiHe.CodeLib
{
    public class DataWriter
    {
        Stream baseStream;

        public DataWriter(Stream stream)
        {
            baseStream = stream;
        }

        public void WriteByte(byte value)
        {
            baseStream.WriteByte(value);
        }

        public void WriteUInt16BE(UInt16 value)
        {
            byte[] bytes = BitConverter.GetBytes(value);
            baseStream.WriteByte(bytes[1]);
            baseStream.WriteByte(bytes[0]);
        }

        public void WriteUInt32BE(UInt32 value)
        {
            byte[] bytes = BitConverter.GetBytes(value);
            baseStream.WriteByte(bytes[3]);
            baseStream.WriteByte(bytes[2]);
            baseStream.WriteByte(bytes[1]);
            baseStream.WriteByte(bytes[0]);
        }

        public void WriteUInt32LE(UInt32 value)
        {
            byte[] bytes = BitConverter.GetBytes(value);
            baseStream.WriteByte(bytes[0]);
            baseStream.WriteByte(bytes[1]);
            baseStream.WriteByte(bytes[2]);
            baseStream.WriteByte(bytes[3]);
        }

        public void WriteBytes(byte[] data)
        {
            baseStream.Write(data, 0, data.Length);
        }

        public void WriteStream(Stream stream)
        {
            byte[] buffer = new byte[stream.Length];
            stream.Position = 0;
            stream.Read(buffer, 0, buffer.Length);
            baseStream.Write(buffer, 0, buffer.Length);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect YunCheDa Hangzhou
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions