你可以試試灑進/從一個字節數組(如在MSDN的Streaming Data from a WAV File描述)。
基本上,在您的LoadContent()
函數中使用TitleContainer.OpenStream(@"soundfile.wav")
可創建System.IO.Stream
對象。然後到BinaryReader
與new BinaryReader(wavStream)
。
閱讀頭:
int chunkID = reader.ReadInt32();
int fileSize = reader.ReadInt32();
int riffType = reader.ReadInt32();
int fmtID = reader.ReadInt32();
int fmtSize = reader.ReadInt32();
int fmtCode = reader.ReadInt16();
int channels = reader.ReadInt16();
int sampleRate = reader.ReadInt32();
int fmtAvgBPS = reader.ReadInt32();
int fmtBlockAlign = reader.ReadInt16();
int bitDepth = reader.ReadInt16();
if (fmtSize == 18)
{
// Read any extra values
int fmtExtraSize = reader.ReadInt16();
reader.ReadBytes(fmtExtraSize);
}
int dataID = reader.ReadInt32();
int dataSize = reader.ReadInt32();
讀取的實際聲音數據:
byteArray = reader.ReadBytes(dataSize);
然後一大堆的複雜的代碼來設置DynamicSoundEffect
對象
(在上面的鏈接詳述)
然後,你可以使用dynamicSound.Play()
和dynamicSound.Stop()
播放和停止你的聲音!
免責聲明:我沒有測試過的播放聲音這種方法,但它從MSDN的所以它可能準確
完美!非常感謝! – BalinKingOfMoria