Lecture12 Java Media Framework I. Streaming Media Steaming media simply means we have a stream of media coming through some kind of a media channel. Some.

Slides:



Advertisements
Similar presentations
Chapter 18 Building the user interface. This chapter discusses n Javas graphical user interface. n Swing: an enhancement of a library called the Abstract.
Advertisements

It provides a framework for embedded multimedia facilities in java enabled mobile devices.
Computer Science 209 Applets. Applications and Applets A Java application runs on a stand-alone computer and may connect to other computers via sockets.
Java Media Framework The Java Media Framework (JMF) is an application programming interface (API) for incorporating time- based media into Java applications.
Lecture13 Java Media Framework II - Java Media Framework II - Processing and Controlling Media with JMF.
Applets The objectives of this chapter are: To describe applets and their purpose To discuss embedding applets in HTML pages.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
1 L45 Multimedia: Applets and Applications. 2 OBJECTIVES  How to get and display images.  To create animations from sequences of images.  To create.
(c) 2006 E.S.Boese All Rights Reserved. Threads and Timers Chapter 19 - Student.
Lecture 24 Applets. Introduction to Applets Applets should NOT have main method but rather init, stop, paint etc They should be run through javac compiler.
Applets. The Applet Class public class MyApplet extends java.applet.Applet {... /** The no-arg constructor is called by the browser when the Web page.
Review of Java Applets Vijayan Sugumaran Decision and Information Sciences Oakland University.
Java Threads A tool for concurrency. OS schedules processes Ready Running 200 Blocked A process loses the CPU and another.
1 Lecturte 14Lecture 7 Applications of Graphics Overview  Conversions Between Applications and Applets  Handling Mouse Events  Handling Keyboard Events.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
JEditorPane Chapter 18 - Student. (c) 2005 by Elizabeth Sugar Boese JEditorPane creation Declare a JEditorPane component. JEditorPane pane; Check to see.
1 Recitation 11. Applet Applets. An applet is a Java program that is started by a browser (e.g. netscape or internet explorer) when an html file has a.
22-Jun-15 Threads and Multithreading. 2 Multiprocessing Modern operating systems are multiprocessing Appear to do more than one thing at a time Three.
1 Introduction of JMF Student : 朱浩廷 Advisor : 杭學鳴 教授.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
 Pearson Education, Inc. All rights reserved Multimedia: Applets and Applications.
Lecture14 Java Media Framework III – Some JMF Applications.
Lecture 17: Animation Yoni Fridman 7/27/01 7/27/01.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
GUI Tutorial Images. Useful Info – not on final exam.
Building a Web Browser CS1316: Representing Structure and Behavior.
CS4273: Distributed System Technologies and Programming I Lecture 3: Java Applets and Animations.
Io package as Java’s basic I/O system continue’d.
Computer Science [3] Java Programming II - Laboratory Course Lab 7: Multimedia: Applets and Applications Faculty of Engineering & IT Software Engineering.
CSTP WS00CS423 (cotter)1 Java Applets Objective: Learn how to develop Java programs that interact with users through a Web browser.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
Applets, AWTS CompSci 230 Software Construction.
 2005 Pearson Education, Inc. All rights reserved Multimedia: Applets and Applications.
(c) 2008 E.S.Boese All Rights Reserved. Threads and Media Chapter 8 - Lecture Slides 1.
Applets Life Cycle Drawing and Event Handling Methods for UI Components Applet Capabilities Example.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Chapter 17: Applets, Images, and Sound. Objectives Learn about applets Write an HTML document to host an applet Use the init() method Work with JApplet.
CIS 644 Aug. 25, 1999 tour of Java. First … about the media lectures… we are experimenting with the media format please give feedback.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Timer Objects  regularly generates action events at programmer-specified time intervals  Timer class is in javax.swing package  Timer (int delay, ActionListener.
Pravin Yannawar, DOCS, NMU Jalgaon Basic Java : Applets 2 Objectives of This Session Identify the need for Applets Distinguish between Applets and Applications.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 16 Applets and Multimedia.
Dynamic Architectures (Component Reconfiguration) with Fractal.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Applets and Multimedia.
Chapter 6 Applets and HTML  Overview  HTML tags for Applets  Applet Life Cycle  Applet Class  JAR files.
An Introduction to Programming and Object Oriented Design using Java 3 rd Edition. Dec 2007 Jaime Niño Frederick Hosch Chapter 18 Integrating user interface.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
CS324e - Elements of Graphics and Visualization Timing Framework.
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
Chapter 8 (Horstmann’s Book) Frameworks Hwajung Lee.
Chapter 8 Frameworks. Frameworks Framework is a set of cooperating classes and interface types that structures the essential mechanisms of a particular.
1 Applets. 2 Design of Applets 3 Sun wrote Java to be executable within a hosting application browser The applications are applets. An applet is downloaded.
Copyright © Curt Hill Applets A different type of program.
Creating a GUI Class An example of class design using inheritance and interfaces.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
CS202 Java Object Oriented Programming GUI Programming – Applets Chengyu Sun California State University, Los Angeles.
Mouse, Keyboard, Sounds, and Images JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,
Java for android Development Nasrullah Khan. Using instanceof in Android Development the classes such as Button, TextView, and CheckBox, which represent.
GUI Programming In Java Sagun Dhakhwa BIM, HSM. GUI Appllications Event Driven OOP Uses objects of Classes like in any other Java programming.
Applet: An applet is a java program that is transmitted over the network from the server to client & executed within clients browser. Applets are used.
Multithreaded applets
Threads in Java Two ways to start a thread
Applets.
Lecture 09 Applets.
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
Applets.
UNIT-5.
11.1 Applets & graphics.
Presentation transcript:

Lecture12 Java Media Framework I

Streaming Media Steaming media simply means we have a stream of media coming through some kind of a media channel. Some identify it as media with a meaningful time dimension.

Audio with Core Java import java.applet.Applet; import java.applet.AudioClip; public class OldAudioClip extends java.applet.Applet { AudioClip aClip; // init() // start() // stop() }

Audio with Core Java public void init() { // TODO start asynchronous download of heavy resources String audioFile; if ((audioFile = getParameter("AUDIOFILE")) == null) { System.err.println("Invalid AUDIOFILE parameter"); System.exit(1); } aClip = getAudioClip(getCodeBase(),audioFile); } public void start() { aClip.loop(); // or aClip.play() } public void stop() { aClip.stop(); }

OLdAudioClip.html Applet HTML Page Applet HTML Page

Player vs. Manager in JMF The main purpose of using JMF is very much to create a player which is capable of playing media such as audio and video. For this purpose JMF has the interface Player. JMF has a class called Manager which has all sort of static create methods, which in particular can create a Player object. There are usually two minimal interactions you do with JMF: Create a Player Start the Player

Creating a Player   In an applet: try { URL url = new URL(getCodeBase(),audioFile); player = Manager.createPlayer(url); } catch (NoPlayerException npe) { System.out.println("Could not create player"); } catch (MalformedURLException mue) { System.out.println("Bad URL"); } catch (IOException ioe) { System.out.println("IO error creating player"); }

Starting/Stopping/Closing a Player public void start() { player.start(); } public void stop() { player.stop(); } Public void distroy() {player.close();}

Looping play in JMF JMF Player object doesn’t have a loop method to loop the play! Looping the play is to do with player controls: for this we have a seperate interface Controller which maintain state information and fires various event objects of type ControllerEvent regarding the play. Just like the event handing architecture of java, the delegation event model, JMF needs objects which can listen to the event objects. These listeners are handled by Controllerlistner interfaces. We can design any class to implement these Controllerlistner interfaces. One of the event object which relate to looping play is EndOfMediaEvent event object. When the listener receives this object, all it has to do to loop the play is to rewind and start again. To start the play, the listener can acquire the source, i.e. the player, via getSourceController method.

Player with ControllerListener for Looping   In an Applet try { URL url = new URL(getCodeBase(),audioFile); player = Manager.createPlayer(url); player.addControllerListener(new LoopListener()); player.start(); } catch (NoPlayerException npe) { System.out.println("Could not create player"); } catch (MalformedURLException mue) { System.out.println("Bad URL"); } catch (IOException ioe) { System.out.println("IO error creating player"); }

ControllerListener for Looping public class LoopListener implements ControllerListener { private Player player; public void controllerUpdate(ControllerEvent event) { player = (Player) event.getSourceController(); if (event instanceof EndOfMediaEvent) { player.setMediaTime(new Time(0)); player.start(); }

Interacting with the Player Just like with a DVD player we would like to interact with the player to do things like pause, volume control, start etc. For this we need to have a control panel which has all the widgets that can perform the required tasks. The Player has getControlPanelComponent method which returns a Component which could be placed into the, say, swing’s JPanel.

The Player States Remember we had the time line. Along this time line, various events occurs, and as these events occurs, Player goes through different states as given in the following order: unrealized : Initial state. Player object instantiated. realizing : Determining required resources and information about media. Acquiring non-exclusive user resources. realized : All non-exclusive use resources have been acquired. prefetched : All resources have been acquired. started : Player is running. Clock has started.

Player Events The story is that the player can give the control panel component only after the realized state. The controller fires the beginning of realized state via RealizeCompleteEvent object. It is the ControllerListener object which capture RealizeCompleteEvent event object and hence it must implement the code to initiate processing the control panel component.

JMF Player Applet with Control Panel public class JMFAudioWithControlPanel extends javax.swing.JApplet { private Player player; private JPanel panel; String audioFile; // public void init() // public void start() // public void distroy() public void distroy(){ player.stop(); player.close(); } // public class AudioControlListener implements //ControllerListener }

init() for JMF Player Applet with Control Panel public void init() { panel = new JPanel(); panel.setLayout(new BorderLayout()); getContentPane().add(panel); if ((audioFile = getParameter("AUDIOFILE")) == null) { System.err.println("Invalid AUDIOFILE parameter"); System.exit(1); }

start() for JMF Player Applet with Control Panel public void start() { try { URL url = new URL(getCodeBase(),audioFile); player = Manager.createPlayer(url); player.addControllerListener(new AudioControlListener()); player.start(); } catch (NoPlayerException npe) { System.out.println("Could not create player"); } catch (MalformedURLException mue) { System.out.println("Bad URL"); } catch (IOException ioe) { System.out.println("IO error creating player"); }

ControllerListener with ControlPanelComponent public class AudioControlListener implements ControllerListener { private Player player; public void controllerUpdate(ControllerEvent event) { player = (Player) event.getSourceController(); if (event instanceof EndOfMediaEvent) { player.setMediaTime(new Time(0)); player.start(); } else if (event instanceof RealizeCompleteEvent){ SwingUtilities.invokeLater(new AddComponentsThread()); } // class AddComponentsThread implements Runnable }

ControlPanelComponent class AddComponentsThread implements Runnable { public void run() { Component cpt = player.getControlPanelComponent(); if (cpt != null) panel.add(cpt, BorderLayout.CENTER); panel.validate(); }

Playing Video We just need to get the visual component and put it at right place in the JPanel. All we need to change in the above program is change AddComponentsThread class which implements the Runnable interface for the GUI components.

Playing Video class AddComponentsThread implements Runnable { private Component controlPanel,visualComponent; public void run() { controlPanel = player.getControlPanelComponent(); if (controlPanel != null) panel.add(controlPanel, BorderLayout.SOUTH); visualComponent = player.getVisualComponent(); if (visualComponent != null) panel.add(visualComponent,BorderLayout.CENTER); panel.validate(); }

Algorithm to play a media object in an applet 1. Obtain the name of media file to play using the getParameter method of Applet. 2. Convert the URL object of the media file using getCodeBase method and the media file name. 3. Create the Player object using the JMF Manager class method createPlayer with the argument as the URL object. 4. Start the Player object. 5. Listen to the Player object events. 6. Wait for the Player object to become realized. 7. At the time of realization: a) a)Obtain the Player object’s visual component (if it exists) and place it on the applet. b) b)Obtain the Player objects’s control panel if required and place it on the applet.