By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,024 Members | 2,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,024 IT Pros & Developers. It's quick & easy.

trouble with executing applets!!!! pl help

P: 2
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.NoClassDefFoundError: javax/media/ControllerListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java :620)
at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:12
4)
at sun.applet.AppletClassLoader.findClass(AppletClass Loader.java:162)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
at sun.applet.AppletClassLoader.loadClass(AppletClass Loader.java:118)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51)
at sun.applet.AppletClassLoader.loadCode(AppletClassL oader.java:577)
at sun.applet.AppletPanel.createApplet(AppletPanel.ja va:710)
at sun.applet.AppletPanel.runLoader(AppletPanel.java: 639)
at sun.applet.AppletPanel.run(AppletPanel.java:319)
at java.lang.Thread.run(Thread.java:595)


Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. import javax.media.*;
  3. import java.awt.*;
  4. import javax.media.protocol.*;
  5. import java.net.*;
  6. import java.util.*;
  7. //import com.sun.media.util.JMFSecurity;
  8. /*
  9. <APPLET CODE = VideoApplet.class WIDTH = 442 HEIGHT = 317 >
  10. <PARAM NAME = CODE VALUE = VideoApplet.class >
  11. <PARAM NAME="type" VALUE="application/x-java-applet;version=1.1">
  12. <PARAM NAME = url VALUE ="FishTank.avi">
  13. <PARAM NAME = url2 VALUE ="FishTank2.avi">
  14. </APPLET>
  15. */
  16. public class VideoApplet extends JApplet implements ControllerListener
  17. {
  18.    // component in which video is playing
  19.     Component visualComponent = null;
  20.     // controls gain, position, start, stop
  21.     Component controlComponent = null;
  22.     // displays progress during download
  23.     Component progressBar = null;
  24.     boolean firstTime = true;
  25.     long CachingSize = 0L;    
  26.         int controlPanelHeight = 0;
  27.     int videoWidth = 0;
  28.     int videoHeight = 0;
  29.     String url;
  30.     MediaLocator locator;
  31.     Player player;
  32.     boolean f=false;
  33.     JPanel panel= new JPanel();
  34.     HashMap urlmap=new HashMap();
  35.     int loopcnt,looptot;
  36. public void init(){
  37.  
  38. looptot=0;
  39. String urls=getParameter("url");
  40. if(urls!=null){
  41.     if(urls.indexOf(",")!=-1){
  42.         StringTokenizer tokens=new StringTokenizer(urls,",");
  43.         while(tokens.hasMoreTokens()){
  44.             String url=tokens.nextToken();
  45.             looptot++;
  46.             System.out.println(" values : "+url+"  : "+looptot);
  47.             urlmap.put(String.valueOf(looptot),url);
  48.         }
  49.     }
  50.     else{
  51.         looptot=1;    
  52.         urlmap.put(String.valueOf(1),urls);
  53.     }
  54. }    
  55.         loopcnt=0;
  56.  
  57.         init2();
  58.     }
  59. public void init2(){
  60. if(looptot<=0)
  61.     return;
  62. loopcnt++;
  63. if(loopcnt>looptot)
  64.     loopcnt=1;
  65.     try {
  66.                url=(String)urlmap.get(String.valueOf(loopcnt));
  67.                URL url2 = new URL(url);
  68.         url = url2.toExternalForm();
  69.         System.out.println(" urlss :: "+url);
  70.             locator = new MediaLocator(url);
  71.             player = Manager.createRealizedPlayer(locator);    
  72.             player.addControllerListener(this);
  73.             panel.add(player.getVisualComponent());
  74.             panel.add(player.getControlPanelComponent());
  75.             getContentPane().add(panel);
  76.             //getContentPane().validate();
  77.             player.start();
  78.         } catch (Exception e) {
  79.             System.out.println("ERROR CREATING MEDIALOCATOR"+e);
  80.             System.exit(-1);
  81.         }
  82.     }
  83.       public void start() {
  84.  System.out.println("Applet.start()11 is called");
  85.         // Call start() to prefetch and start the player.
  86.         if (player != null)
  87.         player.start();
  88.     }
  89.     /**
  90.      * Stop media file playback and release resource before
  91.      * leaving the page.
  92.      */
  93.     public void stop() {
  94.      System.out.println("Applet.stop() is called");
  95.         if (player != null) {
  96.             player.stop();
  97.             player.deallocate();
  98.         }
  99.     }
  100.     public void destroy() {
  101.      System.out.println("Applet.destroy() is called");
  102.     player.close();
  103.     }
  104.       public synchronized void controllerUpdate(ControllerEvent event) {
  105.         System.out.println("Event called");
  106.     // If we're getting messages from a dead player, 
  107.     // just leave
  108.     if (player == null)
  109.         return;
  110.  
  111. if (event instanceof EndOfMediaEvent) {
  112. stop();
  113. destroy();
  114.  
  115.     //getContentPane().removeAll();
  116.     System.out.println("dfdsaf1");
  117.     panel.removeAll();
  118.     //panel.setVisible(false);
  119.     System.out.println("test2");
  120.     init2();
  121.     getContentPane().validate();
  122.     System.out.println("test3");
  123.     //getContentPane().removeAll();
  124. System.out.println("EndOfMediaEvent5  called");
  125. }
  126.  
  127.  
  128.     // When the player is Realized, get the visual 
  129.     // and control components and add them to the Applet
  130.     /*if (event instanceof RealizeCompleteEvent) {
  131.         if (progressBar != null) {
  132.         panel.remove(progressBar);
  133.         progressBar = null;
  134.         }
  135.  
  136.         int width = getWidth();//520;
  137.         int height = 0;
  138.         if (controlComponent == null)
  139.         if (( controlComponent = 
  140.               player.getControlPanelComponent()) != null) {
  141.  
  142.             controlPanelHeight = controlComponent.getPreferredSize().height;
  143.             panel.add(controlComponent);
  144.             height += controlPanelHeight;
  145.         }
  146.         if (visualComponent == null)
  147.         if (( visualComponent =
  148.               player.getVisualComponent())!= null) {
  149.             panel.add(visualComponent);
  150.             Dimension videoSize = visualComponent.getPreferredSize();
  151.             videoWidth = videoSize.width;
  152.             videoHeight = videoSize.height;
  153.             width = videoWidth;
  154.             height += videoHeight;
  155.             visualComponent.setBounds(0, 0, videoWidth, videoHeight);
  156.         }
  157.  
  158.         panel.setBounds(0, 0, width, height);
  159.         if (controlComponent != null) {
  160.         controlComponent.setBounds(0, videoHeight,
  161.                        width, controlPanelHeight);
  162.         controlComponent.invalidate();
  163.         }
  164.         //player.start();
  165.  
  166.      } else if (event instanceof CachingControlEvent) {
  167.         if (player.getState() > Controller.Realizing)
  168.         return;
  169.         // Put a progress bar up when downloading starts, 
  170.         // take it down when downloading ends.
  171.         CachingControlEvent e = (CachingControlEvent) event;
  172.         CachingControl cc = e.getCachingControl();
  173.  
  174.         // Add the bar if not already there ...
  175.         if (progressBar == null) {
  176.             if ((progressBar = cc.getControlComponent()) != null) {
  177.             panel.add(progressBar);
  178.             panel.setSize(progressBar.getPreferredSize());
  179.             validate();
  180.         }
  181.         }
  182.     } else if (event instanceof EndOfMediaEvent) {
  183.  
  184.  
  185.     System.out.println("Applet.EndOfMediaEvent4() called");
  186.         ///////////////////////////
  187.  
  188.  
  189.     } else if (event instanceof ControllerErrorEvent) {
  190.         // Tell TypicalPlayerApplet.start() to call it a day
  191.         System.out.println("Applet errorevent");
  192.         player = null;
  193.         Fatal(((ControllerErrorEvent)event).getMessage());
  194.         } else if (event instanceof ControllerClosedEvent) {
  195.         panel.removeAll();
  196.     }*/
  197.  
  198.  
  199.     }
  200.  
  201.     void Fatal (String s) {
  202.     // Applications will make various choices about what
  203.     // to do here. We print a message
  204.     System.err.println("FATAL ERROR: " + s);
  205.     throw new Error(s); // Invoke the uncaught exception
  206.                 // handler System.exit() is another
  207.                 // choice.
  208.  
  209.     }
  210. }
  211.  
Jan 30 '08 #1
Share this Question
Share on Google+
3 Replies


BigDaddyLH
Expert 100+
P: 1,216
It seems the java plugin doesn't have access to package javax.media. That's not part of the J2SE, right? How do you expect a client machine to access this package?
Jan 30 '08 #2

P: 2
It seems the java plugin doesn't have access to package javax.media. That's not part of the J2SE, right? How do you expect a client machine to access this package?
i've installed JMF... the code i downloaded from ine internet works...... but not mine..... i wanna make mine work....
Jan 30 '08 #3

BigDaddyLH
Expert 100+
P: 1,216
i've installed JMF... the code i downloaded from ine internet works...... but not mine..... i wanna make mine work....
The problems are arising because you are writing an applet. Why not write your example as a standalone application?
Jan 30 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.