Advertisement

04.07.2008 at 12:03PM PDT, ID: 23302347
[x]
Attachment Details

How do I split a WMA/MP3 file into multiple files

Asked by Kevon in Microsoft Development, Microsoft Visual C#.Net, .Net Editors & IDEs

Tags: c#

I have a 800mb wma file that I need to split into multiple files programmatically on the fly by specifying a start and end point in bytes.

I tried doing it by reading a file into a file stream and then writing it back out changing the start position like this.
        Stream GetAudioPiece(Guid key, int start, int stop)
        {
            FileStream Book = new FileStream("d:\\war_peace.wma", FileMode.Open, FileAccess.Read);
            int partSize = stop - start;
            FileStream Part = new FileStream("d:\\war_part.wma", FileMode.Create, FileAccess.Write);

            byte[] buffer = new byte[partSize];

            int data = 0;
            Book.Position = (long)start;
            data = Book.Read(buffer, 0, partSize);
            Part.Write(buffer, 0, data);
            Part.Close();

            FileStream retValue = File.OpenRead("d:\\war_part.wma");

            return retValue;
        }

This didn't work.  I read somewhere that is because WMA files have headers that are required.  So, the question is: How do I read the header from the original file and attach it to the piece I want to stream back?Start Free Trial
 
Loading Advertisement...
 
[+][-]04.08.2008 at 06:32AM PDT, ID: 21304989

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.08.2008 at 08:45AM PDT, ID: 21306390

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.08.2008 at 10:05AM PDT, ID: 21307320

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.10.2008 at 10:17AM PDT, ID: 21327132

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Development, Microsoft Visual C#.Net, .Net Editors & IDEs
Tags: c#
Sign Up Now!
Solution Provided By: Kevon
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628