Java - Multimedia: Applets and applications

Interface Player used to play video Class Manager declares utility methods for accessing system resources to play and manipulate media Manager method createRealizedPlayer obtains a Player for a specified media clip Loading and playing video Player method getVisualComponent gets component that displays visual aspect of media file Player method getControlPanelComponent gets component that provides playback and media controls Player method start begins playing media file

ppt40 trang | Chia sẻ: nguyenlam99 | Lượt xem: 903 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Java - Multimedia: Applets and applications, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
21Multimedia: Applets and Applications 1 The wheel that squeaks the loudest gets the grease.John Billings (Henry Wheeler Shaw)We'll use a signal I have tried and found far-reaching and easy to yell. Waa-hoo!Zane GreyThere is a natural hootchy-kootchy motion to a goldfish.Walt DisneyBetween the motion and the act falls the shadow.Thomas Stearns Eliot2OBJECTIVESIn this chapter you will learn: How to get and display images.How to create animations from sequences of images.How to create image maps.How to get, play, loop and stop sounds, using an AudioClip.How to play video using interface Player.321.1 Introduction 21.2 Loading, Displaying and Scaling Images 21.3 Animating a Series of Images 21.4 Image Maps 21.5 Loading and Playing Audio Clips 21.6 Playing Video and Other Media with Java Media Framework 21.7 Wrap-Up 21.8 Internet and Web Resources 421.1 IntroductionMultimedia – the “sizzle” of JavaSound, images, graphics and videoAn enormous programming fieldDemands extraordinary computing powerMany computer users now want three-dimensional, high-resolution, color graphicsJava provides extensive multimedia facilities, including:Java 3D API – for creating 3D graphics applicationsJMF API – for adding audio and video to an applicationJava Sound API – for playing, recording and modifying audioJava Speech API – for inputting and outputting voice commands521.2 Loading, Displaying and Scaling ImagesClasses Image and ImageIcon – used to load and display imagesDisplaying imagesGraphics method drawImage – used to draw image referenced by Image object (can be scaled)ImageIcon method paintIcon can be used to draw image referenced by ImageIcon objectLoading imagesApplet method getImage loads an Image into an appletApplet method getDocumentBase returns location of applet’s HTML file on InternetImageObservers receive notifications as Image is loaded and update image on screen if it was not complete when displayedJava supports several image formats, including GIF, JPEG and PNG6Returns location of HTML file as URL objectMethod getImage returns Image object for file redflowers.jpgCreate ImageIcon object for file yellowflowers.jpgDraw image stored in redflowers.jpgReturns location of HTML file as URL objectDraw same image scaled to different size78Portability Tip 21.1 Class Image is an abstract class—as a result, programs cannot instantiate class Image to create objects. To achieve platform independence, the Java implementation on each platform provides its own subclass of Image to store image information. 921.3 Animating a Series of ImagesAnimation can be created by displaying a sequence of similar imagesTimer object can be used to specify when each image is displayedTimer objects generate ActionEvents at fixed intervalsMethod start – Timer should start generating eventsMethod stop – Timer should stop generating eventsMethod restart – Timer should start generating events againComponent method getPreferredSize determines the preferred width and height of a componentComponent method getMinimumSize determines the minimum width and height of a component10Will be used to store images to be animated11Create and store ImageIcon for each imageSet next image only if Timer is still running12Create Timer so images will be displayed at intervals of length ANIMATION_DELAYAllow Timer to start generating eventsAllow Timer to start generating events againStop Timer from generating events13Define minimum size for JPanelDefine preferred size for JPanel141516Software Engineering Observation 21.1 When creating an animation for use in an applet, provide a mechanism for disabling the animation when the user browses a new Web page different from the one on which the animation applet resides. 17Look-and-Feel Observation 21.1 The default size of a JPanel object is 10 pixels wide and 10 pixels tall. 18Look-and-Feel Observation 21.2 When subclassing JPanel (or any other JComponent), override method getPreferredSize if the new component is to have a specific preferred width and height. 19Look-and-Feel Observation 21.3 If a new GUI component has a minimum width and height (i.e., smaller dimensions would render the component ineffective on the display), override method getMinimumSize to return the minimum width and height as an instance of class Dimension. 20Look-and-Feel Observation 21.4 For many GUI components, method getMinimumSize is implemented to return the result of a call to the component’s getPreferredSize method.2121.4 Image MapsImage maps used to create interactive Web pagesContains hot areas user can click to accomplish a taskWhen user positions mouse pointer over hot area, normally a descriptive message is displayedApplet method showStatus displays text in an applet container’s status bar222324Method called when mouse is movedCurrent mouse coordinatesDo nothing if mouse is not over an iconDetermine which icon the mouse is overDisplay text for image that mouse is over25262721.5 Loading and Playing Audio ClipsJava programs can play and manipulate audio clipsPlaying sounds in an appletApplet’s play method – loads sound and plays onceAudioClip’s play, loop and stop methodsAdditional capabilities provided by JMF and Java Sound APIsLoading sounds in an appletApplet method getAudioClip – retrieves sound, returns reference to an AudioClipApplet’s play method loads soundSupported file formats include Sun Audio file format, Windows Wave file format, MIDI file format28AudioClip used to represent audio files2930Load audio clips31Play clipPlay clip multiple timesEnd playing of audio clip32Look-and-Feel Observation 21.5 When playing audio clips in an applet or application, provide a mechanism for the user to disable the audio. 3321.6 Playing Video and Other Media with Java Media FrameworkA simple video can concisely and effectively convey a great deal of informationJMF API enables Java programmers to play, edit, stream and capture popular media typesSupported file types include Microsoft Audio/Video Interleave, Macromedia Flash2 movies, MPEG-1 videos and QuickTime movies34Creating a Simple Media PlayerInterface Player used to play videoClass Manager declares utility methods for accessing system resources to play and manipulate mediaManager method createRealizedPlayer obtains a Player for a specified media clipLoading and playing videoPlayer method getVisualComponent gets component that displays visual aspect of media filePlayer method getControlPanelComponent gets component that provides playback and media controlsPlayer method start begins playing media file35Use a lightweight rendererCreate Player for file specified by mediaURLRetrieve components to display video and controls to pause and run video36Play clip37Retrieve file specified by user383940

Các file đính kèm theo tài liệu này:

  • pptjavahtp7e_21_6254.ppt
Tài liệu liên quan