Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2010
    Posts
    2
    Rep Power
    0

    Unhappy Music player problem

    Hi I made a small music player. But when I select the file the windows does not turn up but the music plays in the background and I get these exceptions

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at Musique.openFile(Musique.java:72)
    at Musique.init(Musique.java:37)
    at TaskPanel.actionPerformed(TaskPanel.java:43)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:6134)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3265)
    at java.awt.Component.processEvent(Component.java:589 9)
    at java.awt.Container.processEvent(Container.java:202 3)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4501)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2081)
    at java.awt.Component.dispatchEvent(Component.java:43 31)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4299)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:3963)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:3893)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2067)
    at java.awt.Window.dispatchEventImpl(Window.java:2458 )
    at java.awt.Component.dispatchEvent(Component.java:43 31)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:284)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)

    Here is the code

    Java Code:
    import java.io.*;
    import java.io.FileInputStream.*;
    import java.awt.*;
    import javax.swing.JInternalFrame;
    import javax.swing.UIManager.*;
    import javax.swing.event.InternalFrameEvent;
    import javax.media.*;
    import com.sun.media.ui.*;
    import java.net.*;
    import javax.swing.event.InternalFrameAdapter;
     
    class Musique implements ControllerListener
    { String filename;
        FileDialog fd;
        public void init()
        { core c = new core();
            if (fd == null) 
                            {
                                fd = new FileDialog(c,"Open File",
    						       FileDialog.LOAD);
                            	fd.setDirectory("/movies");
                            }
                            fd.show();
                                if (fd.getFile() != null) {
                                String filename = fd.getDirectory() + fd.getFile();
                                openFile("file:" + filename);
    		    }
                            
                            
        }           
    public void openFile(String filename) {
        //writepadstart w = new writepadstart();
     
    	String mediaFile = filename;
    	Player player = null;
    	// URL for our media file
    	URL url = null;
    	try {
    	    // Create an url from the file name and the url to the
    	    // document containing this applet.
    	    if ((url = new URL(mediaFile)) == null) {
    		Fatal("Can't build URL for " + mediaFile);
    		return;
    	    }
    	    
    	    // Create an instance of a player for this media
    	    try {
    		player = Manager.createPlayer(url);
    	    } catch (NoPlayerException e) {
    		Fatal("Error: " + e);
    	    }
    	} catch (MalformedURLException e) {
    	    Fatal("Error:" + e);
    	} catch (IOException e) {
    	    Fatal("Error:" + e);
    	}
    	if (player != null) {
                core c = new core();
    	    this.filename = filename;
    	    JMFrame1 jmframe = new JMFrame1(player, filename);
    	    c.cont.add(jmframe);
                jmframe.moveToFront();
                jmframe.setClosable(true);
                jmframe.setMaximizable(true);
                jmframe.setIconifiable(true);
                jmframe.setResizable(true);
                jmframe.show();
                
    	}
        }
        
        static void Fatal(String s) {
    	MessageBox mb = new MessageBox("JMF Error", s);
        }    
     
        public void controllerUpdate(ControllerEvent arg0) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
    }
     
     
    class JMFrame1 extends JInternalFrame implements ControllerListener {
        Player mplayer;
        Component visual = null;
        Component control = null;
        int videoWidth = 0;
        int videoHeight = 0;
        int controlHeight = 30;
        int insetWidth = 10;
        int insetHeight = 30;
        boolean firstTime = true;
     
        JMFrame1(Player player, String title) {
            
    	getContentPane().setLayout( new BorderLayout() );
    	setSize(320, 10);
    	setLocation(50, 50);
    	setVisible(true);
    	mplayer = player;
    	mplayer.addControllerListener((ControllerListener) this);
    	mplayer.realize();
    	addInternalFrameListener( new InternalFrameAdapter() {
                @Override
    	    public void internalFrameClosing(InternalFrameEvent ife) {
    		mplayer.close();
    	    }
    	} );
        }
     
        
     
        
        
     
    		    
        
        
        public void controllerUpdate(ControllerEvent ce) {
    	if (ce instanceof RealizeCompleteEvent) {
    	    mplayer.prefetch();
    	} else if (ce instanceof PrefetchCompleteEvent) {
    	    if (visual != null)
    		return;
    	    
    	    if ((visual = mplayer.getVisualComponent()) != null) {
    		Dimension size = visual.getPreferredSize();
    		videoWidth = size.width;
    		videoHeight = size.height;
    		getContentPane().add("Center", visual);
    	    } else
    		videoWidth = 320;
    	    if ((control = mplayer.getControlPanelComponent()) != null) {
    		controlHeight = control.getPreferredSize().height;
    		getContentPane().add("South", control);
    	    }
    	    setSize(videoWidth + insetWidth,
    		    videoHeight + controlHeight + insetHeight);
    	    validate();
    	    mplayer.start();
    	} else if (ce instanceof EndOfMediaEvent) {
    	    mplayer.setMediaTime(new Time(0));
    	    mplayer.start();
    	}
        }
    }

    Sorry for a very very long post..:D

    Moderator edit: code tags added to aid code readability
    Last edited by Fubarable; 02-06-2010 at 06:44 PM. Reason: Code tags added

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    Why the cross post when you have an ongoing discussion on another forum?
    Java Programming - Music player problem

    db

  3. #3
    Join Date
    Feb 2010
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Vlc player interfaces in java
    By sankar1227 in forum Networking
    Replies: 1
    Last Post: 08-06-2011, 09:39 PM
  2. javax.media.Player and JMenu problem
    By nowy in forum AWT / Swing
    Replies: 2
    Last Post: 11-10-2009, 12:49 PM
  3. MP3 Player idea
    By vinoth in forum New To Java
    Replies: 3
    Last Post: 08-18-2009, 02:10 AM
  4. SWT Flash Player
    By forthe in forum SWT / JFace
    Replies: 0
    Last Post: 07-29-2008, 09:48 AM
  5. mp3 player applet
    By willemjav in forum Java Applets
    Replies: 0
    Last Post: 05-20-2008, 02:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •