This article is a detailed guide about playing mp3 audio files into a SIP phone call
in relation with Ozeki VoIP SIP SDK. After reading through this page you will be fully
familiar with all the essential terms concerning playing mp3 into a SIP call and what
you will need for creating your own solution using Ozeki VoIP SIP SDK.
When a VoIP communication software is built there is a need
for the ability of playing audio files into the call like sending audio messages or
using audio data for navigating the caller in an interactive voice response (IVR) System.
The .mp3 format is a collection of audio file definitions that is widely used
among computer users, therefore it is essential to have support for using .mp3 files
in a VoIP solution.
Figure 1 - Incoming SIP message
The following VoIP solution example uses the background support of Ozeki VoIP SIP SDK.
Before you can use the knowledge written in the following section you will need to
download and install Ozeki VoIP SIP SDK on your computer. You will also need to have Visual Studio 2010
and .NET Framework installed as the program below is written in C# language.
Playing audio file
The audio file playing is a basic support in Ozeki VoIP SIP SDK. You can choose
between .wav or .mp3 files and you can play them directly on your speaker or play them
into a SIP call. The example program presented in this article introduces all these variations.
The user interface of this softphone has two new elements, namely groupboxes that
contain the support for the .wav and mp3 playing (Figure 1). The GUI also contains
a groupbox for the PBX registration but that is not different from any simple softphone registration forms,
therefore this article will not cover that topic.
Figure 2 - Graphical user interface for an audio playing softphone
The Ozeki VoIP SIP SDK provides different tools for playing .wav and .mp3 files.
They are special MediaHandler object that can handle the audio streams. Code 1 shows the
audio players that can be used for audio file playing.
Code 1 - The audio player objects
The player objects need a file name or file path to open. On the GUI there is a textbox
for each player. The buttons work similar in both groupboxes, the only difference
is the player object they operate with.
The following code snippets will show the methods for the .mp3 player. The .wav
player's methods work exactly the same way.
As it was mentioned before, you need a file name or path that specifies the .mp3 file to
play. In this example, you can browse for the .mp3 file by pressing the Open button
in the mp3 groupbox. Code 2 shows the event handler for that button.
The first lines of the code make some reinitialization steps. When you want to open a new
audio file to play, both the .mp3 and the .wav file playing tools need to be set back to
the starting states. This means that the actual audio playing, if there is one, should be
stopped, the start buttons need to have the Text "Start" on them (it can be changed to "Pause"
as you will see later) and the file name textboxes need to set empty.
The actual file opening is done by using a standard file open dialog window that
is provided by the C#.Net. You specify the file extension and you get a familiar
pop-up window where you can browse for the .mp3 to play.
When you have chosen the .mp3 file, pressing the OK button will close the window and
the Mp3TextBox will contain the file path for the chosen mp3 file.
Playing an .mp3 file is the key element in this program. You need to initialize the
player object, connect it to the proper MediaHandler(s) and start the streaming.
In this case the Start button in the mp3 groupbox is used for starting and pausing the audio playing.
When you start the playing, the button's text will change to "Pause" and you can use the
same button to pause the stream.
Code 3 shows the event handler method that performs these actions. The first part of
the method is for the initialization if it is necessary - that means that there is no player
The player is only initialized once with the same filename. This means that if you
open the "audiofile.mp3" at the first time, the MP3Playback object will be initialized and
the file path will be stored in the prevmp3file string. When you try to open the
"audiofile.mp3" again, the system checks the file path and for the same file it will not initialize a new
In the second part of the method there is the code for the actual playing and pausing
according to the fact if the stream has been already started or not.
Stopping an mp3 stream (Code 4) can be done by pressing the Stop button in the Mp3 groupbox.
The streaming stops, if there was one, and the Start button will get back the "Start"
Stopping a stream differs from pausing it. In both cases the streaming stops, but in case of pausing, it can be
started again from the point it stopped. In the case of stopping, the stream can only be started from the very beginning.
The player object needs an event handler for the Stopped event. The handling is done
by the tools shown in Code 5.
public event EventHandler<EventArgs> Mp3PlaybackStopped;
void Mp3StreamPlayback_Stopped(object sender, EventArgs e)
if (Mp3PlaybackStopped != null)
Code 5 - The event handlers for the player object
The audio playing is set to play the selected file onto the speaker if there is no
established call or into the call if there is one. You can try every variation and
see how easy is to play an audio file with Ozeki VoIP SIP SDK, and then you can use your
latest knowledge to create your own softphone solution with .wav and/or .mp3 support.
This article introduced you the basic knowledge about playing mp3 audio file into a SIP phone call
and showed how Ozeki VoIP SIP SDK can help you to fulfill your wishes about this topic.
If you have read through this page carefully, you already have all the knowledge you need to start on your own solution.
As you are now familiar with all the terms concerning this topic, now it is time to take a
step further and explore what other extraordinary solution Ozeki VoIP SIP SDK can provide to you.