title: Recording Audio and Playing sound at the same time - C# - Windows Phone 8.1
body: <p>I am trying to record audio and play it directly (I want to hear my voice in the headphone without saving it) however the MediaElement and the MediaCapture seems non to work at the same time.
  I initialized my MediaCapture so:  </p>
  
  <pre><code>    _mediaCaptureManager = new MediaCapture();
      var settings = new MediaCaptureInitializationSettings();
      settings.StreamingCaptureMode = StreamingCaptureMode.Audio;
      settings.MediaCategory = MediaCategory.Other;
      settings.AudioProcessing = AudioProcessing.Default;
      await _mediaCaptureManager.InitializeAsync(settings);
  </code></pre>
  
  <p>However I don't really know how to proceed; I am wonderign if one of these ways could work (I tryied implement them without success, and I have not found examples):</p>
  
  <ol>
  <li>Is there a way to use StartPreviewAsync() recording Audio, or it only works for Videos? I noticed that I get the following error:"The specified object or value does not exist" while setting my CaptureElement Source; it only happens if I write "settings.StreamingCaptureMode = StreamingCaptureMode.Audio;" while everyting works for .Video.</li>
  <li>How can I record to a stream using StartRecordToStreamAsync(); I mean, how have I to initialize the IRandomAccessStream and read from it? Can I <em>write</em> on a stream while I keep <em>reading</em> for it?</li>
  <li><p>I read that changing AudioCathegory of the MediaElement and the MediaCathegory of the MediaCapture to Communication there is a possibility it could work. However, while my code works (it just have to record and save in a file) with the previous setting, it don't works if I wrote "settings.MediaCategory = MediaCategory.Communication;" instead of "settings.MediaCategory = MediaCategory.Other;". Can you tell me why?
  Here is my current program that just record, save and play:  </p>
  
  <pre><code>private async void CaptureAudio()
  {
      try
      {
         _recordStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);                      
        MediaEncodingProfile recordProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.Auto);
        await _mediaCaptureManager.StartRecordToStorageFileAsync(recordProfile, this._recordStorageFile);
        _recording = true;
       }
       catch (Exception e)
       {
          Debug.WriteLine("Failed to capture audio:"+e.Message);
       }
  }
  
  private async void StopCapture()
  {
     if (_recording)
     {
        await _mediaCaptureManager.StopRecordAsync();
        _recording = false;
     }
  }
  
  private async void PlayRecordedCapture()
  {
     if (!_recording)
     {
        var stream = await   _recordStorageFile.OpenAsync(FileAccessMode.Read);
        playbackElement1.AutoPlay = true;
        playbackElement1.SetSource(stream, _recordStorageFile.FileType);
        playbackElement1.Play();
     }
  }
  </code></pre></li>
  </ol>
  
  <p>If you have any suggestion I'll be gratefull.
  Have a good day.</p>