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.

Friday, 28 November 2014

Using XMPP and Openfire server in ASP.NET C# - Part -2

Hi check out my new blog post here on retrieving roster from openfire server in

Roster in XMPP

Roster are the contacts of  user (contact list).

Roster Handlers in AgsXmpp

Let us discuss, the handlers other than the mentioned in part -1 i.e., (loggedin, loginfailed) are mentioned below

·         OnRosterItem

·         OnRosterEnd

·         OnRosterStart

Let us recap part -1 ( ) login part (we need here that code snippet for initializing the above mentioned handlers)

AgsXMPP.XmppClientConnection objXmpp = new agsXMPP.XmppClientConnection ();

Jid jid = new Jid ("xyz@server name"); //ex: –abc is server name

objXmpp.Server = jid.Server;

objXmpp.Username = jid.User;

objXmpp.Password = ******; //your password of account.

objXmpp.AutoResolveConnectServer = true;



 objXmpp.OnLogin += loggedIn; // loggedIn is handler for successful login to server.

 objXmpp.OnAuthError += loginFailed;

objXmpp. OnRosterStart+= new ObjectHandler(objXmpp_OnRosterStart);

objXmpp.OnRosterItem+=new AgsXMPP.XmppClientConnection.RosterHandler(objXmpp_OnRosterItem);

objXmpp. OnRosterEnd+= new ObjectHandler(objXmpp _OnRosterEnd);

objXmpp.Open ();


Catch (exception ex)

{ }

OnRosterStart handler is shown below

 private  void objXmpp_OnRosterStart(object sender)



Onrosterstart handler is executed after the login is successful,  implies initiate any method or variable (ex. DataTable or Generic list to store the contacts ) to handle the Roster List item which is next event.

The OnRosterItem handler is shown below

private void objXmpp_OnRosterItem(object sender, RosterItem rosterItem)



    // rosterItem.Subscription


In the above mentioned handler, we can read every roster information (contact list) after successful OnRosterStart .

We can get below mentioned properties from RosterItem

·         Subscription (SubscriptionType enum )

·         JId

SubscriptionType is an enum with values

·         None – (not yet subscribed)

·         To – (sender subscribed waiting for your approval)

·         From – (receiver not accepted your subscription)

·         Both – (Both receiver and sender accepted the request)

In this event, you can bind the contacts to the required type as explained in onrosterstart.

Add New Roster
We can add new roster to the contacts list by using RosterManager in OnRoserItem

private void addNewRoster(Jid contactJid)


    objXmpp.RosterManager.AddRosterItem(contactJid); // Add new

    objXmpp.RosterManager.UpdateRosterItem(contactJid, "nickname"); //update

    objXmpp.RosterManager.RemoveRosterItem(contactJid); // remove


Approve Subscription
We can approve subscription according to the above mentioned subscription type

private void subcribeRoster(Jid contactJid)




OnRosterEnd handler is shown below

private void objXmpp_OnRosterEnd(object sender)


This handler assures that all Roster all delivered.

(Note: - We cannot use any controls in these handlers to display or update values. Since, these handlers are asynchronous.)

In Part 1 we discussed about Login and Login failed handler.

In Part 2 we discussed about Roster Handlers

And , In Part 3 we shall discuss about sending and Receiving Messages using AgsXmpp.

Firsted posted on

Please, do post feedback.

Monday, 5 May 2014

Using XMPP and Openfire server in ASP.NET C# - Part -1

Extensible Messaging and Presence Protocol (XMPP)

The Extensible Messaging and Presence Protocol (XMPP) is a protocol for streaming XML elements in order to exchange messages and presence information.
The XMPP Core uses main features like
  • XML Streams
  • TLS
  • SASL
  • <message/>, <presence/>, and <iq/> children of the stream root

The basic functionality expected of XMPP is instant messaging (IM) and presence application.

Important requirement are
  •  Exchange messages with other users
  •  Exchange presence information with other users
  •  Manage subscriptions to and from other users
  •  Manage items in a contact list (in XMPP this is called a "roster")
  •  Block communications to or from specific other users

There are many providers who had built in libraries as mentioned in XMPP Standard foundation check link .
The example below described is based on the agsXMPP SDK developed in managed C# dedicated to .NET and Mono technologies. Since, it is dual licensed (GPL) free DLL developed by and they also provide support for issues.
Before moving onto example there is important requirement to implement chat i.e., Chat server installation. I am using Openfire server to fulfill the requirement. For installation follow the link

     Important particulars for this implementation is
  •  JID – Jabber Id, a unique id in the openfire server for each user.
  • Roster- User’s contact is roster.

      How to login to the server?

        Add the following code after successful login from your application.
        AgsXMPP.XmppClientConnection objXmpp = new agsXMPP.XmppClientConnection();
        Jid jid = new Jid ("xyz@server name"); //ex: – is server for  google.mail
       objXmpp.Server = jid.Server;
       objXmpp.Username = jid.User;
objXmpp.Password = ******; //your password of account.
objXmpp.AutoResolveConnectServer = true;
 objXmpp.OnLogin += loggedIn; // loggedIn is handler for successful login to server.
 objXmpp.OnAuthError += loginFailed;
 objXmpp.Open ();
Catch (exception ex)


The loggedin handler is shown below

Private void loggedIn (object o)

//lblStatus.Text = "Logged in and Active.";


The login failed handler is shown below

Private void loginFailed (object o, agsXMPP.Xml.Dom.Element el)

//lblStatus.Text = "Invalid credentials.”


When the loggedin handler executes it assures you that user credentials are valid and logged in.

Part 1 we discussed only on the Login part using AgsXmpp.dll.

In next part i.e., Part 2 we shall discuss upon Recieving roster list of the user using AgsXmpp.