我正在使用 Visual Studio 2013 中的 C# 应用程序,它需要播放 .wav、.mp3 和 .wma 格式的音频文件。.wav 和 mp3 文件播放没有问题。但是,.wma 文件似乎需要额外的处理,我无法找到解决方案。
以下是项目文件顶部的 using 语句:
using NAudio;
using NAudio.Wave;
using NAudio.FileFormats.Wav;
using NAudio.FileFormats.Mp3;
using NAudio.WindowsMediaFormat;
using NAudio.MediaFoundation;
这是播放的代码:
private void PlayIntroScreenAudio()
{
Player.Stop();
byte[] IntroAudioInBytes = Convert.FromBase64String(GameInfo.IntroScreenAudio);
MemoryStream msIntroAudioStream = new MemoryStream(IntroAudioInBytes, 0, IntroAudioInBytes.Length);
msIntroAudioStream.Write(IntroAudioInBytes, 0, IntroAudioInBytes.Length);
msIntroAudioStream.Seek(0, SeekOrigin.Begin);
msIntroAudioStream.Position = 0;
if (GameInfo.IntroScreenAudioFileExt == ".wav")
{
WaveFileReader wfr = new WaveFileReader(msIntroAudioStream);
Player.Init(wfr);
}
else if (GameInfo.IntroScreenAudioFileExt == ".mp3")
{
Mp3FileReader mp3rdr = new Mp3FileReader(msIntroAudioStream);
Player.Init(mp3rdr);
}
else if (GameInfo.IntroScreenAudioFileExt == ".wma")
{
WMAFileReader wmafr = new WMAFileReader(msIntroAudioStream);
Player.Init(wmafr);
}
Player.Play();
IntroAudioIsPlaying = true;
FinalScoreAudioIsPlaying = QuestionAudioIsPlaying = CARAudioIsPlaying = IARAudioIsPlaying = false;
btnPlayIntroScreenAudio.Image = Properties.Resources.btnStopIcon;
btnPlayFinalScoreAudio.Image = btnPlayQuestionAudio.Image = btnPlayCorrectResponseAudio.Image =
btnPlayIncorrectResponseAudio.Image = Properties.Resources.btnPlayIcon;
Player.PlaybackStopped += Player_PlaybackStopped;
}
您可能会猜到,我在“(msIntroAudioStream)”下得到了一条摆动线。我尝试在括号内添加“.ToString()”,但 VS 说这是错误的,因为 wmafr 无法从字符串中读取。播放 .wma 文件还需要哪些其他代码?