Wednesday 31 December 2014

Audio recording in Windows Phone 8 and playing using Media Element

Audio recording in Windows Phone 8 and playing using Media Element


In my present project had required audio recording for windows phone 8 . I was happy to find many samples and examples in google.

But the main problem was I have to store this audio to my DataBase in binary format.I had a ready WCF service to post the data to Database. I was able to get the buffer but the buffer was not in the format to play in media element.

It was very tough task to convert the byte array to .wav format in windows phone 8 . Because the problem was headers missing in the byte array to convert it to valid .wav format.

But it was not able to play . But after many search i found out the audio library for windows phone 8 in codeplex i.e., Coding4Fun.


A beautiful library for getting custom controls in windows phone 8.

Here , I found out that it has audio recorder and returns the data in byte array format of .wav Atlast I find out the required dll.

Shall we start a sample application

  1. Create application ->select windows phone 8 Template - > Sample-Audio

2. Add user control name it as FinalRecorder.xaml (Shows my frustration)

3. Add buttons to Record,Play,Stop,Clear (as per your requirement)


4. Add Media element to play the audio.

 <MediaElement x:Name="MediaElementPlayAudio" MediaEnded="MediaElementPlayAudio_MediaEnded" MediaFailed="MediaElementPlayAudio_MediaFailed"

                          MediaOpened="MediaElementPlayAudio_MediaOpened"></MediaElement>

5. Onclick of Record
  _recorder.Start(); - microphone is activated and started to record.

6. Onclick of Stop
_recorder.Stop(); - microphone is stopped and de-activated .
And Creating audio stream to store the recorded buffer into IsolatedStorageFileStream

7. on click of Play
setting source of media element the audio stream.


Please find the sample application here 


" Happy New Year " Let's Welcome 2015 by thanking 2014 for the beautiful experiences to be in touch with this Blog. Thanks for all the viewers. 

-----------------------------------------Happy Coding -------------------------------------

No comments:

Post a Comment