在C#中播放声音的一部分(WMA)文件 [英] Playing part of a sound (WMA) file in C#
问题描述
我有一个包含许多不同的音频部分的单个WMA文件。
有没有什么办法可以播放声音流的一部分?
是这样的:
公共静态无效播放(流SOUNDSTREAM,长开始,长端);
您可能能够做到这一点使用 n音讯,它是一个净音频库。
IWavePlayer waveOutDevice =新waveout的();
的WaveStream mainOutputStream;
WaveChannel32 volumeStream; 的WaveStream wmaReader =新WMAFileReader(@F:\\我的音乐\\神童\\音乐的抛弃代\\ 01 Intro.wma);
volumeStream =新WaveChannel32(wmaReader); mainOutputStream = volumeStream; mainOutputStream.Skip(30); // 30秒开始到文件
waveOutDevice.Init(mainOutputStream);
waveOutDevice.Play();
以上省略样品清理$ C C停止播放并不过流处理。希望有点帮助。
I have a single WMA file which contains lots of different pieces of audio. Is there any way I can play part of a sound stream?
Something like:
public static void Play(Stream soundStream, long start, long end);
You may be able to do this using NAudio, it is a audio library for .Net.
Using the example here I was able to throw a quick test application up to try it. Using the WaveSteam.Skip(int seconds) method you are able to start at a specific position in the file. I have not been able to work out how to get the end position though. Below is the modified sample that starts a wma file at the 30 second mark:
IWavePlayer waveOutDevice = new WaveOut();
WaveStream mainOutputStream;
WaveChannel32 volumeStream;
WaveStream wmaReader = new WMAFileReader(@"F:\My Music\The Prodigy\Music for the Jilted Generation\01 Intro.wma");
volumeStream = new WaveChannel32(wmaReader);
mainOutputStream = volumeStream;
mainOutputStream.Skip(30); //start 30 seconds into the file
waveOutDevice.Init(mainOutputStream);
waveOutDevice.Play();
The above sample omits the cleanup code to stop playback and dispose of the streams however. Hope that helps a bit.
这篇关于在C#中播放声音的一部分(WMA)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!