在IE10中捕获麦克风

时间:2013-08-30 18:20:25

标签: javascript internet-explorer audio blob getusermedia

我需要在IE10中捕获麦克风音频。到目前为止,我有两个半工作解决方案:

有没有其他方法可以在IE10中捕获音频?

1 个答案:

答案 0 :(得分:0)

我认识到我的回答有点晚了,但...... 您可以将blob上传到服务器,如下所示(Javascript):

function saveBlob(blob)
{
   var uploader = new CustomXMLHttpRequest();
   uploader.onpartreceived = function (response)
   {
     // TODO: handle the server response here
   };

   var base = window.location.toString();
   var uploadService = base.substr(0, base.lastIndexOf("/")) + "/api/upload";

   uploader.open("POST", uploadService, true);

   uploader.responseType = "text";

   var form = new FormData();
   form.append("fname", blob, "audio.wav");

   uploader.send(form);
}

在服务器端,您可以将此blob视为文件附件,例如(C#):

public class UploadController : ApiController
{
   public async Task<HttpResponseMessage> PostFile()
   {
      // Check if the request contains multipart/form-data.
      if (!Request.Content.IsMimeMultipartContent())
      {
        throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
      }

      var root = HttpContext.Current.Server.MapPath("~/App_Data");
      var provider = new MultipartFormDataStreamProvider(root);

      try
      {
        // Read the form data and return an async task.
        await Request.Content.ReadAsMultipartAsync(provider);

        var fileName = "";

        // get the uploaded files.
        foreach (var data in provider.FileData)
        {
          var file = new FileInfo(data.LocalFileName);

          // TODO: handle received file here
        }

        if (string.IsNullOrEmpty(fileName))
        {
          return Request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
        }

        return Request.CreateResponse(HttpStatusCode.OK);
      }
      catch (System.Exception e)
      {
        return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
      }
  }
}

希望这会有所帮助。