locked
Windows Store App Audio Recorder

    Question

  • I am creating a windows store app for recording audio.The below is the code:-

    //Declared the object of MediaCapture and IRandomAccessStream class.

    private MediaCapture CaptureMedia; private IRandomAccessStream AudioStream;

    //Initialized both the above declared objects

    CaptureMedia = new MediaCapture(); AudioStream = new InMemoryRandomAccessStream();

    //On the record button I have used the "StartRecordToStreamAsync()" method of CaptureMedia

    await CaptureMedia.StartRecordToStreamAsync(encodingProfile, AudioStream);

    // On the stop button I have used the "StopRecordAsync()" method

    await CaptureMedia.StopRecordAsync();

    // I am saving the recorded audio as on the Save button click event

    private async void SaveBtn_Click(object sender, RoutedEventArgs e) { var mediaFile = await FileSave.PickSaveFileAsync();

            if (mediaFile != null)
            {
                using (var dataReader = new DataReader(AudioStream.GetInputStreamAt(0)))
                {
                    await dataReader.LoadAsync((uint)AudioStream.Size);
                    byte[] buffer = new byte[(int)AudioStream.Size];
                    dataReader.ReadBytes(buffer);
                    await FileIO.WriteBytesAsync(mediaFile, buffer);
                    UpdateRecordingControls(RecordingMode.Initializing);
                }
            }
        }
    

    Everything is working fine for now. And I want to Add the Option to Pause the audio recording and then resume recording from the save point where the audio was paused. But there is no method for pausing the recording.

    Please help me how to do it or guide me some other ways to pause the audio recording.

    Thanks,

    Friday, February 21, 2014 7:19 AM

Answers

  • Hello,

    Theoretically as long as the random access stream is not closed and the position is not changed you should be able to continue recording to the stream after stop is called. Keep in mind this may not work as you expect for compressed formats but should work for uncompressed formats such as PCM.

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Friday, February 21, 2014 11:43 PM
    Moderator

All replies

  • I'll ask Media experts to check out this post.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, February 21, 2014 8:40 PM
    Moderator
  • Hello,

    Theoretically as long as the random access stream is not closed and the position is not changed you should be able to continue recording to the stream after stop is called. Keep in mind this may not work as you expect for compressed formats but should work for uncompressed formats such as PCM.

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Friday, February 21, 2014 11:43 PM
    Moderator