Archive for August, 2007

Chapter 22 Java Media Framework and Java Sound (Fedora web server)

Friday, August 31st, 2007

Chapter 22 Java Media Framework and Java Sound (on CD) 1249 Performance Tip 22.1 Starting the Player takes less time if the Player has already prefetched the media before invoking start. When the media clip ends, the Player generates a ControllerEvent of type EndOfMediaEvent. Most media players rewind the media clip after reaching the end so users can see or hear it again from the beginning. Method endOfMedia (lines 249 253) handles the EndOfMediaEventand resets the media clip to its beginning position by invoking Player method setMediaTime with a new Time (package javax.media) of 0 (line 251). Method setMediaTime sets the position of the media to a specific time location in the media, and is useful for jumping to a different part of the media. Line 252 invokes Player method stop, which ends media processing and places the Player in state Stopped. Invoking method start on a Stopped Player that has not been closed resumes media playback. Often, it is desirable to configure the media before presentation. In the next section, we discuss interface Processor, which has more configuration capabilities than interface Player. Processors enable a program to format media and to save it to a file. 22.3 Formatting and Saving Captured Media The Java Media Framework supports playing and saving media from capture devices such as microphones and video cameras. This type of media is known as captured media. Capture devices convert analog media into digitized media. For example, a program that captures an analog voice from a microphone attached to computer can create a digitized file from a that recording. The JMF can access video capture devices that use Video for Windows drivers. Also, JMF supports audio capture devices that use the Windows Direct Sound Interface or the Java Sound Interface. The Video for Windows driver provides interfaces that enable Windows applications to access and process media from video devices. Similarly, Direct Sound and Java Sound are interfaces that enable applications to access sound devices such as hardware sound cards. The Solaris Performance Pack provides support for Java Sound and Sun Video capture devices on the Solaris platform. For a complete list of devices supported by JMF, visit JMF s official Web site. The SimplePlayer application presented in Fig. 22.1 allowed users to play media from a capture device. A locator string specifies the location of a capture device that the SimplePlayer demo accesses. For example, to test the SimplePlayer s capturing capabilities, plug a microphone into a sound card s microphone input jack. Typing the locator string javasound:// in the Open Location input dialog specifies that media should be input from the Java Sound-enabled capture device. The locator string initializes the Media- Locator that the Player needs for the audio material captured from the microphone. Although SimplePlayer provides access to capture devices, it does not format the media or save captured data. Figure 22.2 presents a program that accomplishes these two new tasks. Class CapturePlayerprovides more control over media properties via class DataSource (package javax.media.protocol). Class DataSource provides the connection to the media source, then abstracts that connection to allow users to manipulate it. This program uses a DataSource to format the input and output media. The DataSourcepasses the formatted output media to a Controller, which will format it
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Web file server - 1248 Java Media Framework and Java Sound (on

Friday, August 31st, 2007

1248 Java Media Framework and Java Sound (on CD) Chapter 22 completes realizing, it generates a RealizeCompleteEvent a type of ControllerEvent that occurs when a Player completes its transition to state Realized. This state indicates that the Playerhas completed all preparations needed to start processing the media. The program invokes method realizeComplete (lines 228 232) when Player generates a RealizeCompleteEvent. Most media players have a buffering feature, which stores a portion of downloaded media locally so that users do not have to wait for an entire clip to download before playing it, as reading media data can take a long time. By invoking Player method prefetch, line 231 transitions the player to the Prefetching state. When a Player prefetches a media clip, the Playerobtains exclusive control over certain system resources needed to play the clip. The Playeralso begins buffering media data to reduce the delay before the media clip plays. When the Player completes prefetching, it transitions to state Prefetched and is ready to play media. During this transition, the Player generates a ControllerEvent of type PrefetchCompleteEvent to indicate that it is ready to display media. The Player invokes PlayerEventHandler method prefetchComplete (lines 235 246), which displays the Player s GUI in the frame. After obtaining the hardware resources, the program can get the media components it requires. Line 238 invokes method getMediaComponents (lines 206 222) to obtain the GUI s controls and the media s visual component (if the media is a video clip) and attach them to the application window s content pane. Player method getVisualComponent (line 209) obtains the visual component of the video clip. Similarly, line 216 invokes Player method getControl- PanelComponentto return the GUI s controls. The GUI (Fig. 22.1) typically provides the following controls: 1. A positioning slider to jump to certain points in the media clip. 2. A pause button. 3. A volume button that provides volume control by right clicking and a mute function by left clicking. 4. A media properties button that provides detailed media information by right clicking and frame rate control by left clicking. Look-and-Feel Observation 22.1 Invoking Playermethod getVisualComponentyields null for audio files, because there is no visual component to display. Look-and-Feel Observation 22.2 Invoking Player method getControlPanelComponent yields different sets of GUI controls depending on the media type. For example, media content streamed directly from a live conference does not have a progress bar because the length of the media is not pre-determined. After validating the new frame layout (line 241), line 244 invokes Player method start (line 239) to start playing the media clip. Software Engineering Observation 22.1 If the Player has not prefetched or realized the media, invoking Player method start prefetches and realizes the media.
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

Chapter 22 (Web hosting domain) Java Media Framework and Java Sound

Thursday, August 30th, 2007

Chapter 22 Java Media Framework and Java Sound (on CD) 1247 is one) using lightweight renderers so that the media player will look like other GUIs with Swing components. By default, Player s video components are heavyweight components, which may not display correctly when mixed with lightweight Swing GUI components. Before playing the media, SimplePlayer displays an initial GUI consisting of two buttons, Open File and Open Locator, that enable users to specify the media location. The event handlers for these two buttons (lines 52 78 and lines 90 101) perform similar functions. Each button prompts users for a media resource such as an audio or video clip, then creates a Player for the specified media. When the user clicks Open File, line 57 calls method getFile (lines 120 134) to prompt users to select a media file from the local computer. Line 63 calls the File method toURL to obtain a URL representation of the selected file s name and location. Line 72 calls SimplePlayer method makePlayer (lines 150 187) to create a Playerfor the user-selected media. When users click Open Locator, line 95 invokes method getMediaLocation (lines 137 147), prompting users to input a String giving the media location. Line 98 calls SimplePlayer method makePlayer to create a Player for the media at the specified location. Method makePlayer (lines 150 187) makes the necessary preparations to create a Player of media clips. The String argument indicates the media s location. Lines 153 154 invoke SimplePlayer method removePlayerComponents (lines 191 203) to remove the previous Player s visual component and GUI controls from the frame before creating a new Player. Line 202 invokes Player method close to stop all player activity and to release system resources held by the previous Player. Method makePlayer requires a pointer to the source from which the media is retrieved, which is accomplished by instantiating a new MediaLocator for the value given by the String argument (lines 157 158). A MediaLocator specifies the location of a media source, much like a URL typically specifies the location of a Web page. A MediaLocator can access media from capture devices and RTP sessions as well as from file locations. The MediaLocator constructor requires the media s location as a String, so all URLs must be converted to Strings as in line 72. Method makePlayer instantiates a new Player with a call to Manager method createPlayer. Class Manager provides static methods that enable programs to access most JMF resources. Method createPlayer opens the specified media source and determines the appropriate Player for the media source. Method createPlayer throws a NoPlayerException if an appropriate Player cannot be found for the media clip. An IOException is thrown if there are problems connecting to the media source. ControllerListeners listen for the ControllerEvents that Players generate to track the progress of a Player in the media-handling process. Lines 170 171 register an instance of inner class PlayerEventHandler (lines 225 255) to listen for certain events that player generates. Class PlayerEventHandler extends class ControllerAdapter, which provides empty implementations of methods from interface ControllerListener. Class ControllerAdapter facilitates implementing ControllerListener for classes that need to handle only a few Controller- Event types. Players confirm their progress while the processing media based on their state transitions. Line 174 invokes Player method realize to confirm all resources necessary to play media are available. Method realize places the Player in the Realizing state to indicate that it is connecting to and interacting with its media sources. When a Player
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

1246 Java Media Framework and Java Sound (on (Make a web site)

Wednesday, August 29th, 2007

1246 Java Media Framework and Java Sound (on CD) Chapter 22 Fig. 22.1 Playing media with interface Player(part 8 of 8) . A media clip must be processed before it is played. To process a media clip the program must access a media source, create a Controller for that source and output the media. Prior to output, users may perform optional formatting such as changing an AVI video to a QuickTime video. Although JMF hides low-level media processing (e.g. checking for file compatibility) from the programmer, both programmers and users can configure how a Player presents media. Section 22.3 and Section 22.4 reveal that capturing and streaming media follow the same guidelines. Section 22.8 lists several Web sites that have JMF-supported media contents. Figure 22.1 introduces some key objects for playing media. The JMF extension package javax.media imported in line 13 contains interface Player and other classes and interfaces needed for events. Line 18 declares a Playerobject to play media clips. Lines 30 31 declare the location of these clips as Fileand URLreferences. Lines 21 and 24 declare Component objects for the video display and for holding the controls. Component mediaControl enables users to play, pause and stop the media clip. ComponentvisualMedia displays the video portion of a media clip (if the media clip is a video). The JMF provides lightweight video renderers that are compatible with lightweight Swing components (See Chapter 13). Lines 107 108 in SimplePlayer s constructor specify that the Playershould draw its GUI components and video portion (if there
We recommend high quality webhost to host and run your jsp application: christian web host services.

Chapter 22 Java (Cheap web hosting) Media Framework and Java Sound

Wednesday, August 29th, 2007

Chapter 22 Java Media Framework and Java Sound (on CD) 1245 Fig. 22.1 Playing media with interface Player(part 7 of 8) .
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

1244 Java Media Framework and Java Sound (on (Web hosts)

Tuesday, August 28th, 2007

1244 Java Media Framework and Java Sound (on CD) Chapter 22 254 255 } // end PlayerEventHandler inner class 256 257 // execute application 258 public static void main( String args[] ) 259 { 260 SimplePlayer testPlayer = new SimplePlayer(); 261 262 testPlayer.setSize( 300, 300 ); 263 testPlayer.setLocation( 300, 300 ); 264 testPlayer.setDefaultCloseOperation( EXIT_ON_CLOSE ); 265 testPlayer.setVisible( true ); 266 } 267 268 } // end class SimplePlayer Fig. 22.1 Playing media with interface Player(part 6 of 8) .
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Chapter 22 Java Media Framework and Java Sound (Msn web hosting)

Tuesday, August 28th, 2007

Chapter 22 Java Media Framework and Java Sound (on CD) 1243 201 // stop player and return allocated resources 202 player.close(); 203 } 204 205 // obtain visual media and player controls 206 public void getMediaComponents() 207 { 208 // get visual component from player 209 visualMedia = player.getVisualComponent(); 210 211 // add visual component if present 212 if ( visualMedia != null ) 213 container.add( visualMedia, BorderLayout.CENTER ); 214 215 // get player control GUI 216 mediaControl = player.getControlPanelComponent(); 217 218 // add controls component if present 219 if ( mediaControl != null ) 220 container.add( mediaControl, BorderLayout.SOUTH ); 221 222 } // end method getMediaComponents 223 224 // handler for player’s ControllerEvents 225 private class PlayerEventHandler extends ControllerAdapter { 226 227 // prefetch media feed once player is realized 228 public void realizeComplete( 229 RealizeCompleteEvent realizeDoneEvent ) 230 { 231 player.prefetch(); 232 } 233 234 // player can start showing media after prefetching 235 public void prefetchComplete( 236 PrefetchCompleteEvent prefetchDoneEvent ) 237 { 238 getMediaComponents(); 239 240 // ensure valid layout of frame 241 validate(); 242 243 // start playing media 244 player.start(); 245 246 } // end prefetchComplete method 247 248 // if end of media, reset to beginning, stop play 249 public void endOfMedia( EndOfMediaEvent mediaEndEvent ) 250 { 251 player.setMediaTime( new Time( 0 ) ); 252 player.stop(); 253 } Fig. 22.1 Playing media with interface Player(part 5 of 8) .
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

1242 Java Media Framework and Java Sound (on (Domain and web hosting)

Tuesday, August 28th, 2007

1242 Java Media Framework and Java Sound (on CD) Chapter 22 148 149 // create player using media’s location 150 public void makePlayer( String mediaLocation ) 151 { 152 // reset player and window if previous player exists 153 if ( player != null ) 154 removePlayerComponents(); 155 156 // location of media source 157 MediaLocator mediaLocator = 158 new MediaLocator( mediaLocation ); 159 160 if ( mediaLocator == null ) { 161 showErrorMessage( “Error opening file” ); 162 return; 163 } 164 165 // create a player from MediaLocator 166 try { 167 player = Manager.createPlayer( mediaLocator ); 168 169 // register ControllerListener to handle Player events 170 player.addControllerListener( 171 new PlayerEventHandler() ); 172 173 // call realize to enable rendering of player’s media 174 player.realize(); 175 } 176 177 // no player exists or format is unsupported 178 catch ( NoPlayerException noPlayerException ) { 179 noPlayerException.printStackTrace(); 180 } 181 182 // file input error 183 catch ( IOException ioException ) { 184 ioException.printStackTrace(); 185 } 186 187 } // end makePlayer method 188 189 // return player to system resources and 190 // reset media and controls 19 public void removePlayerComponents() 19 { 19 // remove previous video component if there is one 19 if ( visualMedia != null ) 19 container.remove( visualMedia ); 19 19 // remove previous media control if there is one 19 if ( mediaControl != null ) 19 container.remove( mediaControl ); 200 Fig. 22.1 Playing media with interface Player(part 4 of 8) .
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

Chapter 22 (Web site developers) Java Media Framework and Java Sound

Monday, August 27th, 2007

Chapter 22 Java Media Framework and Java Sound (on CD) 1241 95 String addressName = getMediaLocation(); 96 97 if ( addressName != null ) 98 makePlayer( addressName ); 99 } 100 101 } // end ActionListener 102 103 ); // end call to method addActionListener 104 105 // turn on lightweight rendering on players to enable 106 // better compatibility with lightweight GUI components 107 Manager.setHint( Manager.LIGHTWEIGHT_RENDERER, 108 Boolean.TRUE ); 109 110 } // end SimplePlayer constructor 111 112 // utility method for pop-up error messages 113 public void showErrorMessage( String error ) 114 { 115 JOptionPane.showMessageDialog( this, error, “Error”, 116 JOptionPane.ERROR_MESSAGE ); 117 } 118 119 // get file from computer 120 public File getFile() 121 { 122 JFileChooser fileChooser = new JFileChooser(); 123 124 fileChooser.setFileSelectionMode( 125 JFileChooser.FILES_ONLY ); 126 127 int result = fileChooser.showOpenDialog( this ); 128 129 if ( result == JFileChooser.CANCEL_OPTION ) 130 return null; 131 132 else 133 return fileChooser.getSelectedFile(); 134 } 135 136 // get media location from user input 137 public String getMediaLocation() 138 { 139 String input = JOptionPane.showInputDialog( 140 this, “Enter URL” ); 141 142 // if user presses OK with no input 143 if ( input != null && input.length() == 0 ) 144 return null; 145 146 return input; 147 } Fig. 22.1 Playing media with interface Player(part 3 of 8) .
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Web design tools - 1240 Java Media Framework and Java Sound (on

Monday, August 27th, 2007

1240 Java Media Framework and Java Sound (on CD) Chapter 22 42 container.add( buttonPanel, BorderLayout.NORTH ); 43 44 // opening file from directory button 45 JButton openFile = new JButton( “Open File” ); 46 buttonPanel.add( openFile ); 47 48 // register an ActionListener for openFile events 49 openFile.addActionListener( 50 51 // anonymous inner class to handle openFile events 52 new ActionListener() { 53 54 // open and create player for file 55 public void actionPerformed( ActionEvent event ) 56 { 57 mediaFile = getFile(); 58 59 if ( mediaFile != null ) { 60 61 // obtain URL from file 62 try { 63 fileURL = mediaFile.toURL(); 64 } 65 66 // file path unresolvable 67 catch ( MalformedURLException badURL ) { 68 badURL.printStackTrace(); 69 showErrorMessage( “Bad URL” ); 70 } 71 72 makePlayer( fileURL.toString() ); 73 74 } 75 76 } // end actionPerformed 77 78 } // end ActionListener 79 80 ); // end call to method addActionListener 81 82 // URL opening button 83 JButton openURL = new JButton( “Open Locator” ); 84 buttonPanel.add( openURL ); 85 86 // register an ActionListener for openURL events 87 openURL.addActionListener( 88 89 // anonymous inner class to handle openURL events 90 new ActionListener() { 91 92 // open and create player for media locator 93 public void actionPerformed( ActionEvent event ) 94 { Fig. 22.1 Playing media with interface Player(part 2 of 8) .
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.