オーディオ ファイルを .wav、.mp3、および .wma 形式で再生する必要がある Visual Studio 2013 の C# アプリに取り組んでいます。.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() を追加しようとしましたが、wmafr は文字列から読み取ることができないため、VS はそれが間違っていると言います。.wma ファイルを再生するには、他にどのようなコードが必要ですか?