Title: Programming with JMF
1Programming with JMF
- Prepared by Tony K. C. Chan.
2Learning Objectives
- Foundation of media communications
- Setup the voice communication channel with Java
Media Framework (JMF) - Complete the simplified Internet phone system
31. Background Knowledge
- Java Media Framework (JMF) API for time-based
media in Java. - Processing model
41. Background Knowledge
- Some Important Terms in JMF
- DataSource an object thatencapsulates the media
stream(e.g., a file, an incoming stream,etc.). - Capture device hardware used to capture the
media data (e.g., microphone).
51. Background Knowledge
- Some Important Terms in JMF, cont.
- Player
- a media handler forrendering and
controllingtime-based media data. - Processing model of the Player
61. Background Knowledge
- Some Important Terms in JMF, cont.
- Player, cont.
- Six states of the Player
71. Background Knowledge
- Some Important Terms in JMF, cont.
- Processor
- It extends the Player interface.
- Rendering media data
- Control over the processing of the input output
media data. - Processing model of the Processor
81. Background Knowledge
- Some Important Terms in JMF, cont.
- Processor, cont.
- Processing stages of the Processor
91. Background Knowledge
- Some Important Terms in JMF, cont.
- Processor, cont.
- Two additional states (Configuring Configured).
101. Background Knowledge
- Some Important Terms in JMF, cont.
- Format represents the exact format of the media
(e.g., GSM). - Manager
- used to implement some other interfaces
- Example
- Manager ? Player, Processor, and DataSource.
- CaptureDeviceManager ? access a list of available
capture devices. - RTPManater used to create, maintain and close an
RTP session.
111. Background Knowledge
- Some Useful Event
- ConfigureCompleteEvent
- posed when a Processor finishes Configuring.
- occurs when a Processor moves from Configuring to
Configured (i.e., Processor is already
Configured). - RealizeCompleteEvent
- posted when a Controller finishes Realizing.
- occurs when a Controller moves from Realizing to
Realized (i.e., the Controller is already
Realized).
121. Background Knowledge
- Some Useful Event, cont.
- EndOfMediaEvent
- indicates that the Controller has reached the end
of its media and is stopping. - NewReceiveStreamEvent
- Informs the RTP listener that a new stream of RTP
data packets has been detected
132. Programming with JMF
- Setting up Your Computer
- Setting up the Recording Control
- Setting up the Volume Control
- Testing with Sound Recorder
142. Programming with JMF
- Playing Media File Using JMF
- Create MediaLocator that represents the
mediaMediaLocator mediaLocator new
MediaLocator(fileName) - Create DataSource for the MediaLocatordataSource
Manager.createDataSource( mediaLocator) - Create Player for the DataSourceplayer
Manager.createPlayer(dataSource)
152. Programming with JMF
- Playing Media File Using JMF, cont.
- Add ControllerListener to the playerplayer.addCon
trollerListener(this) - Implement the controllerUpdate methodpublic
synchronized void controllerUpdate(
ControllerEvent e) ... - Realize the Playerplayer.realize()
- Start the Playerplayer.start()
162. Programming with JMF
- Playing Media File Using JMF, cont.
/ File name RingPlayer.java / import
java.media. import java.media.protocol. publi
c class RingPlayer Player player public
RingPlayer() String fileName
file//C\\java\\ringin.wav ... public
void start() ... public void stop() ...
172. Programming with JMF
- Playing Media File Using JMF, cont.
public class RingPlayer implements
ControllerListener Player player public
RingPlayer() String fileName
file//C\\java\\ringin.wav ...
player.addControllerListener(this) ...
... public synchronized void controllerUpate(
ControllerEvent e) if (e instanceof
EndOfMediaEvent) player.setMediaTime(new
Time(0)) ...
183. The ChattingManager for our SIPS
- Details of ChattingManager
- ChattingManager(int mediaPort)
- Creates an instance of ChattingManager.
- Capture the audio device from your computer and
prepare all stuff for setting up the voice
communication channel. - ChattingManager(int mediaPort, boolean
showProgress) - Same as ChattingManager(int mediaPort), but with
debugging output.
193. The ChattingManager for our SIPS
- Details of ChattingManager, cont.
- void setupConnection(InetAddress targetIP, int
targetPort) sets up the RTP session with the
remote host and waiting for receiving audio
stream. - void start() start sending the captured audio
stream through the connected RTP session. - void destroy() stop and destroy the RTP session
(it will not destroy the ChattingManager).
203. The ChattingManager for our SIPS
- How to use the ChattingManager
- Save ChattingManager.class and SendProcessor.class
in the working directory
21THE END