如何保存的byte [],如Silverlight应用程序wav文件? [英] How to save byte[] as wav file in silverlight application?

查看:111
本文介绍了如何保存的byte [],如Silverlight应用程序wav文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的MVC应用程序,我添加一个Silverlight录音机。这台录音机录制音频使用System.Windows.Media; 命名空间字节[] 的再presents的WAV文件中。

In my MVC Application I added a Silverlight Audio Recorder. This recorder record audio using System.Windows.Media; namespace as byte[] that represents an wav file.

现在我需要保存这个字节[] .WAV 本地磁盘(服务器)文件。

Now I need to save this byte[] as .wav file on local disk (server).

到目前为止,我已经尝试了以下内容:

So far I've tried the following:

byte[] audioData; // Here I contain my data     

System.IO.File.WriteAllBytes(@"C:\Temp\yourfile.wav", this.audioData); // Doesn't work

BinaryWriter Writer = null;
string name = @"C:\Temp\yourfile.wav";

try
{
      Writer = new BinaryWriter(File.OpenWrite(name));

      Writer.Write(this.audioData);
      Writer.Flush();
      Writer.Close();
 }
 catch
 {
      ...
 }

但对我来说没有什么工作......我做了什么错?

But nothing work for me... What I did wrong?

确定。比方说,我可以把我的数据作为JSON字符串到控制器:

Ok. Let's say I can send my data as json string to the controller:

WebClient net = new WebClient();
string data = UTF8Encoding.UTF8.GetString(this.audioData, 0, this.audioData.Length);

net.UploadStringAsync(new Uri("/Home/SaveFile", UriKind.Relative), data);

我怎么会在MVC行动得到这个数据?

How would I get this data in MVC Action?

推荐答案

Silverlight是运行客户端,你的MVC code是服务器端,所以这不会工作,这是当前的幌子。

Silverlight is running client side, your MVC code is server-side, so this won't work in it's current guise.

我推荐使用Web服务将数据发送回服务器保存。

I'd recommend using a web service to send the data back to your server to save it.

看看使用 WCF 或者的WebAPI 起床,并运行它。

Take a look at using WCF or maybe WebAPI to get up and running with it.

如果你真的想做得到复杂的,你也可以使用类似 SignalR 有客户机/服务器(这基本上是什么这个设置​​是)寄送相互通信,并通过将数据发送回。虽然看似一个的的矫枉过正这一点。

If you really wanted to do get intricate, you could also use something like SignalR to have the client / server (which is essentially what this set up is) send communicate with each other and send the data back through that. Though it seems a little overkill for this.

这篇关于如何保存的byte [],如Silverlight应用程序wav文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆