2012-07-31 3 views
0

.wav 파일이 있는데이 바이트 형식을 XML에 씁니다. 이 노래를 제 형식으로 연주하고 싶지만 제가 틀렸다고 확신하지 못하고 작동하지 않습니다. Str은 내 파일의 바이트 형식입니다.XML 사운드의 바이트 형식

byte[] soundBytes = Convert.FromBase64String(str); 
MemoryStream ms = new MemoryStream(soundBytes, 0, soundBytes.Length); 
ms.Write(soundBytes, 0, soundBytes.Length); 
SoundPlayer ses = new SoundPlayer(ms); 
ses.Play(); 

답변

1

나는 문제가 당신이 버퍼로 MemoryStream를 초기화하고 스트림에 같은 버퍼를 작성라고 생각합니다. 따라서 스트림은 주어진 데이터 버퍼로 시작한 다음 동일한 버퍼로 덮어 쓰지 만 그 과정에서 스트림의 현재 위치도 끝까지 변경합니다.

byte[] soundBytes = Convert.FromBase64String(str); 
MemoryStream ms = new MemoryStream(soundBytes, 0, soundBytes.Length); 
// ms.Position is 0, the beginning of the stream 
ms.Write(soundBytes, 0, soundBytes.Length); 
// ms.Position is soundBytes.Length, the end of the stream 
SoundPlayer ses = new SoundPlayer(ms); 
// ses tries to play from a stream with no more bytes to consume 
ses.Play(); 

ms.Write()으로 전화를 제거하고 작동하는지 확인하십시오.