如何按顺序播放多个音频文件?

时间:2021-02-07 15:21:56

In my C# application, I need to play multiple audio files (WAV and MP3) one after the other. How can I accomplish that?

在我的C#应用​​程序中,我需要一个接一个地播放多个音频文件(WAV和MP3)。我怎么能做到这一点?

2 个解决方案

#1


CodeProject have several examples that shows how to play audio. Once you get the hang of that playing multiple files after each other should be easy.

CodeProject有几个示例演示如何播放音频。一旦你掌握了相互之后播放多个文件应该很容易。

  1. A low-level audio player in C#
  2. C#中的低级音频播放器

  3. Playing .wav files using C#
  4. 使用C#播放.wav文件

  5. Audio Player using winmm.dll and WPL File
  6. 音频播放器使用winmm.dll和WPL文件

  7. A simple class to allow you to play Wavs in C#
  8. 一个简单的类,允许你在C#中玩Wavs

I find that working directly with winmm.dll is pretty easy. My recomendation is to start with example 3

我发现直接使用winmm.dll很容易。我的推荐是从例3开始

#2


Example Using NAudio for WAV files

示例将NAudio用于WAV文件

 private List<string> wavlist = new List<string>();
 wavlist.Add("c:\\1.wav");
 wavlist.Add("c:\\2.wav");
 foreach(string file  in wavlist)
 {
      AudioFileReader audio = new AudioFileReader(file);
      audio.Volume = 1;
      IWavePlayer player = new WaveOut(WaveCallbackInfo.FunctionCallback());
      player.Init(audio);
      player.Play();
      System.Threading.Thread.Sleep(audio.TotalTime);
      player.Stop();
      player.Dispose();
      audio.Dispose();
      player = null;
      audio = null;
  }

#1


CodeProject have several examples that shows how to play audio. Once you get the hang of that playing multiple files after each other should be easy.

CodeProject有几个示例演示如何播放音频。一旦你掌握了相互之后播放多个文件应该很容易。

  1. A low-level audio player in C#
  2. C#中的低级音频播放器

  3. Playing .wav files using C#
  4. 使用C#播放.wav文件

  5. Audio Player using winmm.dll and WPL File
  6. 音频播放器使用winmm.dll和WPL文件

  7. A simple class to allow you to play Wavs in C#
  8. 一个简单的类,允许你在C#中玩Wavs

I find that working directly with winmm.dll is pretty easy. My recomendation is to start with example 3

我发现直接使用winmm.dll很容易。我的推荐是从例3开始

#2


Example Using NAudio for WAV files

示例将NAudio用于WAV文件

 private List<string> wavlist = new List<string>();
 wavlist.Add("c:\\1.wav");
 wavlist.Add("c:\\2.wav");
 foreach(string file  in wavlist)
 {
      AudioFileReader audio = new AudioFileReader(file);
      audio.Volume = 1;
      IWavePlayer player = new WaveOut(WaveCallbackInfo.FunctionCallback());
      player.Init(audio);
      player.Play();
      System.Threading.Thread.Sleep(audio.TotalTime);
      player.Stop();
      player.Dispose();
      audio.Dispose();
      player = null;
      audio = null;
  }