This is a code i wrote to play a video file usin JMF..... the applet gets started but not initialized.... . is the code correct or is there any mistake?????? please help me out as soon as u can......need to get this right as soon as i can.........
the input goes through the varialbles url and url2------ location of the file
this is the error i get
java.lang.NoCla ssDefFoundError : javax/media/ControllerListe ner
at java.lang.Class Loader.defineCl ass1(Native Method)
at java.lang.Class Loader.defineCl ass(ClassLoader .java:620)
at java.security.S ecureClassLoade r.defineClass(S ecureClassLoade r.java:12
4)
at sun.applet.Appl etClassLoader.f indClass(Applet ClassLoader.jav a:162)
at java.lang.Class Loader.loadClas s(ClassLoader.j ava:306)
at sun.applet.Appl etClassLoader.l oadClass(Applet ClassLoader.jav a:118)
at java.lang.Class Loader.loadClas s(ClassLoader.j ava:251)
at sun.applet.Appl etClassLoader.l oadCode(AppletC lassLoader.java :577)
at sun.applet.Appl etPanel.createA pplet(AppletPan el.java:710)
at sun.applet.Appl etPanel.runLoad er(AppletPanel. java:639)
at sun.applet.Appl etPanel.run(App letPanel.java:3 19)
at java.lang.Threa d.run(Thread.ja va:595)
[CODE=Java]
import javax.swing.*;
import javax.media.*;
import java.awt.*;
import javax.media.pro tocol.*;
import java.net.*;
import java.util.*;
//import com.sun.media.u til.JMFSecurity ;
/*
<APPLET CODE = VideoApplet.cla ss WIDTH = 442 HEIGHT = 317 >
<PARAM NAME = CODE VALUE = VideoApplet.cla ss >
<PARAM NAME="type" VALUE="applicat ion/x-java-applet;version= 1.1">
<PARAM NAME = url VALUE ="FishTank.avi" >
<PARAM NAME = url2 VALUE ="FishTank2.avi ">
</APPLET>
*/
public class VideoApplet extends JApplet implements ControllerListe ner
{
// component in which video is playing
Component visualComponent = null;
// controls gain, position, start, stop
Component controlComponen t = null;
// displays progress during download
Component progressBar = null;
boolean firstTime = true;
long CachingSize = 0L;
int controlPanelHei ght = 0;
int videoWidth = 0;
int videoHeight = 0;
String url;
MediaLocator locator;
Player player;
boolean f=false;
JPanel panel= new JPanel();
HashMap urlmap=new HashMap();
int loopcnt,looptot ;
public void init(){
looptot=0;
String urls=getParamet er("url");
if(urls!=null){
if(urls.indexOf (",")!=-1){
StringTokenizer tokens=new StringTokenizer (urls,",");
while(tokens.ha sMoreTokens()){
String url=tokens.next Token();
looptot++;
System.out.prin tln(" values : "+url+" : "+looptot);
urlmap.put(Stri ng.valueOf(loop tot),url);
}
}
else{
looptot=1;
urlmap.put(Stri ng.valueOf(1),u rls);
}
}
loopcnt=0;
init2();
}
public void init2(){
if(looptot<=0)
return;
loopcnt++;
if(loopcnt>loop tot)
loopcnt=1;
try {
url=(String)url map.get(String. valueOf(loopcnt ));
URL url2 = new URL(url);
url = url2.toExternal Form();
System.out.prin tln(" urlss :: "+url);
locator = new MediaLocator(ur l);
player = Manager.createR ealizedPlayer(l ocator);
player.addContr ollerListener(t his);
panel.add(playe r.getVisualComp onent());
panel.add(playe r.getControlPan elComponent());
getContentPane( ).add(panel);
//getContentPane( ).validate();
player.start();
} catch (Exception e) {
System.out.prin tln("ERROR CREATING MEDIALOCATOR"+e );
System.exit(-1);
}
}
public void start() {
System.out.prin tln("Applet.sta rt()11 is called");
// Call start() to prefetch and start the player.
if (player != null)
player.start();
}
/**
* Stop media file playback and release resource before
* leaving the page.
*/
public void stop() {
System.out.prin tln("Applet.sto p() is called");
if (player != null) {
player.stop();
player.dealloca te();
}
}
public void destroy() {
System.out.prin tln("Applet.des troy() is called");
player.close();
}
public synchronized void controllerUpdat e(ControllerEve nt event) {
System.out.prin tln("Event called");
// If we're getting messages from a dead player,
// just leave
if (player == null)
return;
if (event instanceof EndOfMediaEvent ) {
stop();
destroy();
//getContentPane( ).removeAll();
System.out.prin tln("dfdsaf1");
panel.removeAll ();
//panel.setVisibl e(false);
System.out.prin tln("test2");
init2();
getContentPane( ).validate();
System.out.prin tln("test3");
//getContentPane( ).removeAll();
System.out.prin tln("EndOfMedia Event5 called");
}
// When the player is Realized, get the visual
// and control components and add them to the Applet
/*if (event instanceof RealizeComplete Event) {
if (progressBar != null) {
panel.remove(pr ogressBar);
progressBar = null;
}
int width = getWidth();//520;
int height = 0;
if (controlCompone nt == null)
if (( controlComponen t =
player.getContr olPanelComponen t()) != null) {
controlPanelHei ght = controlComponen t.getPreferredS ize().height;
panel.add(contr olComponent);
height += controlPanelHei ght;
}
if (visualComponen t == null)
if (( visualComponent =
player.getVisua lComponent())!= null) {
panel.add(visua lComponent);
Dimension videoSize = visualComponent .getPreferredSi ze();
videoWidth = videoSize.width ;
videoHeight = videoSize.heigh t;
width = videoWidth;
height += videoHeight;
visualComponent .setBounds(0, 0, videoWidth, videoHeight);
}
panel.setBounds (0, 0, width, height);
if (controlCompone nt != null) {
controlComponen t.setBounds(0, videoHeight,
width, controlPanelHei ght);
controlComponen t.invalidate();
}
//player.start();
} else if (event instanceof CachingControlE vent) {
if (player.getStat e() > Controller.Real izing)
return;
// Put a progress bar up when downloading starts,
// take it down when downloading ends.
CachingControlE vent e = (CachingControl Event) event;
CachingControl cc = e.getCachingCon trol();
// Add the bar if not already there ...
if (progressBar == null) {
if ((progressBar = cc.getControlCo mponent()) != null) {
panel.add(progr essBar);
panel.setSize(p rogressBar.getP referredSize()) ;
validate();
}
}
} else if (event instanceof EndOfMediaEvent ) {
System.out.prin tln("Applet.End OfMediaEvent4() called");
///////////////////////////
} else if (event instanceof ControllerError Event) {
// Tell TypicalPlayerAp plet.start() to call it a day
System.out.prin tln("Applet errorevent");
player = null;
Fatal(((Control lerErrorEvent)e vent).getMessag e());
} else if (event instanceof ControllerClose dEvent) {
panel.removeAll ();
}*/
}
void Fatal (String s) {
// Applications will make various choices about what
// to do here. We print a message
System.err.prin tln("FATAL ERROR: " + s);
throw new Error(s); // Invoke the uncaught exception
// handler System.exit() is another
// choice.
}
}
[/CODE]
the input goes through the varialbles url and url2------ location of the file
this is the error i get
java.lang.NoCla ssDefFoundError : javax/media/ControllerListe ner
at java.lang.Class Loader.defineCl ass1(Native Method)
at java.lang.Class Loader.defineCl ass(ClassLoader .java:620)
at java.security.S ecureClassLoade r.defineClass(S ecureClassLoade r.java:12
4)
at sun.applet.Appl etClassLoader.f indClass(Applet ClassLoader.jav a:162)
at java.lang.Class Loader.loadClas s(ClassLoader.j ava:306)
at sun.applet.Appl etClassLoader.l oadClass(Applet ClassLoader.jav a:118)
at java.lang.Class Loader.loadClas s(ClassLoader.j ava:251)
at sun.applet.Appl etClassLoader.l oadCode(AppletC lassLoader.java :577)
at sun.applet.Appl etPanel.createA pplet(AppletPan el.java:710)
at sun.applet.Appl etPanel.runLoad er(AppletPanel. java:639)
at sun.applet.Appl etPanel.run(App letPanel.java:3 19)
at java.lang.Threa d.run(Thread.ja va:595)
[CODE=Java]
import javax.swing.*;
import javax.media.*;
import java.awt.*;
import javax.media.pro tocol.*;
import java.net.*;
import java.util.*;
//import com.sun.media.u til.JMFSecurity ;
/*
<APPLET CODE = VideoApplet.cla ss WIDTH = 442 HEIGHT = 317 >
<PARAM NAME = CODE VALUE = VideoApplet.cla ss >
<PARAM NAME="type" VALUE="applicat ion/x-java-applet;version= 1.1">
<PARAM NAME = url VALUE ="FishTank.avi" >
<PARAM NAME = url2 VALUE ="FishTank2.avi ">
</APPLET>
*/
public class VideoApplet extends JApplet implements ControllerListe ner
{
// component in which video is playing
Component visualComponent = null;
// controls gain, position, start, stop
Component controlComponen t = null;
// displays progress during download
Component progressBar = null;
boolean firstTime = true;
long CachingSize = 0L;
int controlPanelHei ght = 0;
int videoWidth = 0;
int videoHeight = 0;
String url;
MediaLocator locator;
Player player;
boolean f=false;
JPanel panel= new JPanel();
HashMap urlmap=new HashMap();
int loopcnt,looptot ;
public void init(){
looptot=0;
String urls=getParamet er("url");
if(urls!=null){
if(urls.indexOf (",")!=-1){
StringTokenizer tokens=new StringTokenizer (urls,",");
while(tokens.ha sMoreTokens()){
String url=tokens.next Token();
looptot++;
System.out.prin tln(" values : "+url+" : "+looptot);
urlmap.put(Stri ng.valueOf(loop tot),url);
}
}
else{
looptot=1;
urlmap.put(Stri ng.valueOf(1),u rls);
}
}
loopcnt=0;
init2();
}
public void init2(){
if(looptot<=0)
return;
loopcnt++;
if(loopcnt>loop tot)
loopcnt=1;
try {
url=(String)url map.get(String. valueOf(loopcnt ));
URL url2 = new URL(url);
url = url2.toExternal Form();
System.out.prin tln(" urlss :: "+url);
locator = new MediaLocator(ur l);
player = Manager.createR ealizedPlayer(l ocator);
player.addContr ollerListener(t his);
panel.add(playe r.getVisualComp onent());
panel.add(playe r.getControlPan elComponent());
getContentPane( ).add(panel);
//getContentPane( ).validate();
player.start();
} catch (Exception e) {
System.out.prin tln("ERROR CREATING MEDIALOCATOR"+e );
System.exit(-1);
}
}
public void start() {
System.out.prin tln("Applet.sta rt()11 is called");
// Call start() to prefetch and start the player.
if (player != null)
player.start();
}
/**
* Stop media file playback and release resource before
* leaving the page.
*/
public void stop() {
System.out.prin tln("Applet.sto p() is called");
if (player != null) {
player.stop();
player.dealloca te();
}
}
public void destroy() {
System.out.prin tln("Applet.des troy() is called");
player.close();
}
public synchronized void controllerUpdat e(ControllerEve nt event) {
System.out.prin tln("Event called");
// If we're getting messages from a dead player,
// just leave
if (player == null)
return;
if (event instanceof EndOfMediaEvent ) {
stop();
destroy();
//getContentPane( ).removeAll();
System.out.prin tln("dfdsaf1");
panel.removeAll ();
//panel.setVisibl e(false);
System.out.prin tln("test2");
init2();
getContentPane( ).validate();
System.out.prin tln("test3");
//getContentPane( ).removeAll();
System.out.prin tln("EndOfMedia Event5 called");
}
// When the player is Realized, get the visual
// and control components and add them to the Applet
/*if (event instanceof RealizeComplete Event) {
if (progressBar != null) {
panel.remove(pr ogressBar);
progressBar = null;
}
int width = getWidth();//520;
int height = 0;
if (controlCompone nt == null)
if (( controlComponen t =
player.getContr olPanelComponen t()) != null) {
controlPanelHei ght = controlComponen t.getPreferredS ize().height;
panel.add(contr olComponent);
height += controlPanelHei ght;
}
if (visualComponen t == null)
if (( visualComponent =
player.getVisua lComponent())!= null) {
panel.add(visua lComponent);
Dimension videoSize = visualComponent .getPreferredSi ze();
videoWidth = videoSize.width ;
videoHeight = videoSize.heigh t;
width = videoWidth;
height += videoHeight;
visualComponent .setBounds(0, 0, videoWidth, videoHeight);
}
panel.setBounds (0, 0, width, height);
if (controlCompone nt != null) {
controlComponen t.setBounds(0, videoHeight,
width, controlPanelHei ght);
controlComponen t.invalidate();
}
//player.start();
} else if (event instanceof CachingControlE vent) {
if (player.getStat e() > Controller.Real izing)
return;
// Put a progress bar up when downloading starts,
// take it down when downloading ends.
CachingControlE vent e = (CachingControl Event) event;
CachingControl cc = e.getCachingCon trol();
// Add the bar if not already there ...
if (progressBar == null) {
if ((progressBar = cc.getControlCo mponent()) != null) {
panel.add(progr essBar);
panel.setSize(p rogressBar.getP referredSize()) ;
validate();
}
}
} else if (event instanceof EndOfMediaEvent ) {
System.out.prin tln("Applet.End OfMediaEvent4() called");
///////////////////////////
} else if (event instanceof ControllerError Event) {
// Tell TypicalPlayerAp plet.start() to call it a day
System.out.prin tln("Applet errorevent");
player = null;
Fatal(((Control lerErrorEvent)e vent).getMessag e());
} else if (event instanceof ControllerClose dEvent) {
panel.removeAll ();
}*/
}
void Fatal (String s) {
// Applications will make various choices about what
// to do here. We print a message
System.err.prin tln("FATAL ERROR: " + s);
throw new Error(s); // Invoke the uncaught exception
// handler System.exit() is another
// choice.
}
}
[/CODE]
Comment