Я пытаюсь отправить байты звуковых данных из Windows Phone 7 в Java-сервлет App Engine. Где-то по пути данные облажались, и когда я пытаюсь воспроизвести звук, это не работает. Вот часть кода:
WP7:
public static void SendEmail(byte[] data, String to, String subject, String filename)
{
//WebClient wc = new WebClient();
//wc.Headers[HttpRequestHeader.ContentType] = "application/binary";
String url = "http://someserver/test?to=" + to + "&subject=" + subject + "&filename=" + filename;
//wc.OpenReadAsync(new Uri(url), "POST");
var webClient = new WebClient();
webClient.OpenWriteAsync(new Uri(url), "POST", data);
webClient.OpenWriteCompleted += new OpenWriteCompletedEventHandler(webClient_OpenWriteCompleted);
}
static void webClient_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e)
{
object[] objArr = e.UserState as object[];
byte[] fileContent = e.UserState as byte[];
Stream outputStream = e.Result;
outputStream.Write(fileContent, 0, fileContent.Length);
outputStream.Flush();
outputStream.Close();
}
Сервлет App Engine:
InputStream in = req.getInputStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int next = in.read();
while (next > -1) {
bos.write(next);
next = in.read();
}
bos.flush();
attachmentData = bos.toByteArray();
Wp7 аудио код:
microphone.GetData(buffer);
stream.Write(buffer, 0, buffer.Length);
//then I save the stream.toArray() to an object and use it later for playback on the phone
Java-код для создания аудио (аудио отправляется в виде вложения в электронное письмо):
MimeBodyPart attachmentPart = new MimeBodyPart();
attachmentPart.setFileName(filename + ".wav");
attachmentPart.setDisposition(Part.ATTACHMENT);
DataSource src = new ByteArrayDataSource(attachmentData, "audio/x-wav");
DataHandler handler = new DataHandler(src);
attachmentPart.setDataHandler(handler);
mp.addBodyPart(attachmentPart);