60 likes | 78 Views
Discover how to open files with JFileChooser and play video with Java Media Framework efficiently. Learn about file selection, rendering hints, media playback, exceptions, and player controls.
E N D
Opening Files with JFileChooser • The class JFileChooser • Enables the user to easily select files or directories • JFileChooser method setFileSelectionMode • Specifies what the user can select from the file chooser • JFileChooser static constant • FILES_AND_DIRECTORIES indicates that • files and directories can be selected. • Method showOpenDialog displays • a JFileChooser dialog titled Open.
Opening Files with JFileChooser • A JFileChooser dialog is a modal dialog box. • Method showOpenDialog • returns an integer specifying which • button (Open or Cancel) the user clicked to close the dialog • JFileChooser method getSelectedFile • returns the selected file as a File object.
Playing Video and Other Media with Java Media Framework • static Manager method setHint • specifies rendering hints to the Manager. • e.g., instructs the Manager to use a lightweight renderer • that is compatible with lightweight Swing components, • as opposed to the default heavyweight renderer. • static method createRealizedPlayer of Manager • creates and realizes a Player that plays the media file. • When a Player realizes, it identifies the system resources • it needs to play the media. • Depending on the file, realizing can be • a resource-consuming and time-consuming process.
Playing Video and Other Media with JMF • Throws three checked exceptions, • NoPlayerException, • CannotRealizeException and • IOException. • A NoPlayerException indicates that the system • could not find a player that can play the file format. • A CannotRealizeException indicates that the system • could not properly identify the resources a media file needs. • An IOException indicates that • there was an error while reading the file.
Playing Video and Other Media with JMF (cont’d) • Player method getVisualComponent gets • a Component that displays the visual (generally video) aspect • of the media file. • Player method getControlPanelComponent gets • a Component that provides playback and media controls. • Player method start begins playing a media file. • Method toURI of class File returns a URI that • points to the File on the system. • Then, method toURL of class URI get the file’s URL.