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"


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 -------------------------------------

Tuesday, 16 December 2014

PDF creation using Sharp-PDF C#

Simple example for creating PDF file using Sharp-PDF


I came across a new library for developing PDF in C# named as SharpPDF . It is open source .net dll . Find the URL here .

You will find many tutorials on the net. But, I thought of sharing what I know (not completely).

Hoping for ?

A generic class to create pdf with different generic objects and mail it as attachment.



Lets get on

There are many objects that is supported by SharpPDF . Below are just a glimpse of objects supported in SharpPDF and used here in the post are
  • Text Object
  • Image Object
  • Table Object

The main class is pdfDocument for preparing document.

Here we can add text or background image(Logo) using PdfDocument document .

PdfTable is the table object as specified above . Where , we use maximum of these objects
in PDF generation.

I have created a class PDFGenerate which has some properties included . And there is a Method CreatePDF with generic List (List<T> ) as input.

It will create PDF and save to the folder PDF in application.

Please find the guide related to the sharp pdf in below mentioned URL

If there are any changes required and any guidance are accepted happily.