This is an All-In-One Code Framework (http://1code.codeplex.com) sample to be published as KB. The sample package and the KBdraft are attached. The samples in the project are featured by:
1) Sample Source: The samples are refined out of CSS developer supports forcustomers. You can think of the samples as a collection of most frequentlyasked coding scenarios in contrast with FAQs.
2) Three Languages: Almost all samples are provided in three popularprogramming languages: VC# and VB.NET when applicable.
3) All-In-One: All sample for all Microsoft development techniques are in onesolution.
4) Simple build and run experience.
How to extract and convertaudio file formats
This article describes anAll-In-One Code Framework sample that is available for download. The sample demonstrates how to extract and convert audiofile formats, which include wav, mp3 and mp4 files.
The sample is used to extractmusic file formats. We usually play music with Windows Media Player or othermusic-playing software. If we find our favorite music clip, we can use thefunction of this sample to extract it and convert it into another file format.All technology mentioned above is based on Expression Encoder SDK 4.0. When youinstall Expression Encoder 4.0, you can use Visual Studio 2010 to add areference to it. In this way, you don't have to install the SDK installationkits individually.
The sample uses ExpressionEncoder SDK 4 to output *.mp4 or *.wma file. The .mp3 audio format is currentlynot supported as output format in Expression Encoder 4.
Difficulty Level
Medium
1. Usefollowing helper function to cut the audio file from startpoint to endpoint,and output the clip as the selected audio format.
public static string ExtractAudio(string sourceAudioFile, string outputDirectory,
OutputAudioType outputAudioType, double startpoint, double endpoint)
{
using (Job job = new Job())
{
MediaItem src = new MediaItem(sourceAudioFile);
switch (outputAudioType)
{
case OutputAudioType.MP4:
src.OutputFormat = new MP4OutputFormat();
src.OutputFormat.AudioProfile = new AacAudioProfile();
src.OutputFormat.AudioProfile.Codec = AudioCodec.AAC;
src.OutputFormat.AudioProfile.BitsPerSample = 24;
break;
case OutputAudioType.WMA:
src.OutputFormat = new WindowsMediaOutputFormat();
src.OutputFormat.AudioProfile = new WmaAudioProfile();
src.OutputFormat.AudioProfile.Bitrate = new VariableConstrainedBitrate(128, 192);
src.OutputFormat.AudioProfile.Codec = AudioCodec.WmaProfessional;
src.OutputFormat.AudioProfile.BitsPerSample = 24;
break;
}
TimeSpan spanStart = TimeSpan.FromMilliseconds(startpoint);
src.Sources[0].Clips[0].StartTime = spanStart;
TimeSpan spanEnd = TimeSpan.FromMilliseconds(endpoint);
src.Sources[0].Clips[0].EndTime = spanEnd;
job.MediaItems.Add(src);
job.OutputDirectory = outputDirectory;
job.Encode();
return job.MediaItems[0].ActualOutputFileFullPath;
}
}
2. Use the Windows Media Player control to play thesource audio file. The following MSDN article introduces how to embed theWindows Media Player ActiveX control in a Windows Form. http://msdn.microsoft.com/en-us/library/dd562851.aspx
For more information about how to create and deploy thesample application, see the Readme.txt file that is included in the downloadpackage.
Network
Language |
Project Name |
Visual C# |
CSExtractAudioFile |
Visual Basic.NET |
VBExtractAudioFile |
Thissample application was created by using Visual Studio 2010, .NETFramework 4 and Microsoft Expression Encoder 4.
Expression Encoder SDKProgramming Reference
http://msdn.microsoft.com/en-us/library/ff396833(v=Expression.40).aspx
Microsoft Expression Encoder 4FAQ
http://social.expression.microsoft.com/Forums/en/encoder/thread/3eabf903-b49f-4f92-b508-f28a795d6c90