在C#中播放声音的一部分(WMA)文件 [英] Playing part of a sound (WMA) file in C#

查看:197
本文介绍了在C#中播放声音的一部分(WMA)文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含许多不同的音频部分的单个WMA文件。
有没有什么办法可以播放声音流的一部分?

是这样的:

 公共静态无效播放(流SOUNDSTREAM,长开始,长端);


解决方案

您可能能够做到这一点使用 n音讯,它是一个净音频库。

使用示例我是能够抛出一个快速测试应用程序rel=\"nofollow\"> ,跃跃欲试。使用WaveSteam.Skip(中间体秒)的方法,你都能够在该文件中的特定位置开始。我一直没能制定出如何让终端位置虽然。下面是在30秒标记启动wma文件修改后的示例:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆