Results 1 to 3 of 3

Thread: media player

  1. #1
    rithish is offline Member
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Default media player

    hello i want to build a media player but i dont know the logic i searched for codings i didnt get proper one i got this one that is wrong
    Java Code:
     import java.awt.*;
     import java.awt.event.*;
     import java.io.*;
     import javax.swing.*;
     import javax.media.*;
    
     public class MediaPlayerDemo extends JFrame 
     {
    	 private Player player;
    	 private File file;
    
    	 public MediaPlayerDemo()
    	 {
    		 super( "Demonstrating the Java Media Player" );
    
    		 JButton openFile = new JButton( "Open file to play" );
    		 openFile.addActionListener( new ActionListener() 
    		 {
    			 public void actionPerformed( ActionEvent e )
    			 {
    				 openFile();
    				 createPlayer();
    			 }
    		 });
    		 getContentPane().add( openFile, BorderLayout.NORTH );
    
    		 setSize( 300, 300 );
    		 show();
    	 }
    
    	 private void openFile()
    	 {
    		 JFileChooser fileChooser = new JFileChooser();
    
    		 fileChooser.setFileSelectionMode( JFileChooser.FILES_ONLY );
    		 int result = fileChooser.showOpenDialog( this );
    
    		 // user clicked Cancel button on dialog
    		 if ( result == JFileChooser.CANCEL_OPTION )
    			 file = null;
    		 else
    			 file = fileChooser.getSelectedFile();
    	 }
    
    	 private void createPlayer()
    	 {
    		 if ( file == null )
    			 return;
    
    		 removePreviousPlayer();
    
    		 try 
    		 {
    			 // create a new player and add listener
    			 player = Manager.createPlayer( file.toURL() );
    			 player.addControllerListener( new EventHandler() );
    			 player.start(); // start player
    		 }
    		 catch ( Exception e )
    		 {
    			 JOptionPane.showMessageDialog( this, "Invalid file or location", "Error loading file",
    			 JOptionPane.ERROR_MESSAGE );
    		 }
    	 }
    
    	 private void removePreviousPlayer()
    	 {
    		 if ( player == null )
    			 return;
    
    		 player.close();
    
    		 Component visual = player.getVisualComponent();
    		 Component control = player.getControlPanelComponent();
    
    		 Container c = getContentPane();
    
    		 if ( visual != null )
    			 c.remove( visual );
    
    		 if ( control != null )
    			 c.remove( control );
    	 }
    
    	 public static void main(String args[])
    	 {
    		 MediaPlayerDemo app = new MediaPlayerDemo();
    
    		 app.addWindowListener( new WindowAdapter() 
    		 {
    			 public void windowClosing( WindowEvent e )
    			 {
    				 System.exit(0);
    			 }
    		 });
    	 }
    
    	 // inner class to handler events from media player
    	 private class EventHandler implements ControllerListener 
    	 {
    		 public void controllerUpdate( ControllerEvent e ) 
    		 {
    			 if ( e instanceof RealizeCompleteEvent ) 
    			 {
    				 Container c = getContentPane();
    
    				 // load Visual and Control components if they exist
    				 Component visualComponent = player.getVisualComponent();
    
    				 if ( visualComponent != null )
    					 c.add( visualComponent, BorderLayout.CENTER );
    
    				 Component controlsComponent = player.getControlPanelComponent();
    
    				 if ( controlsComponent != null )
    					 c.add( controlsComponent, BorderLayout.SOUTH );
    
    				 c.doLayout();
    			 }
    		 }
    	 }
     }
    can i get sample tutorial of media player

  2. #2
    rithish is offline Member
    Join Date
    Apr 2011
    Posts
    39
    Rep Power
    0

    Default

    please help me

  3. #3
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    It is impossible to program without knowing that logic of what you are trying to code.
    I think you have to wirte down the feature that you want to have on your media player,
    then try to create a class that meet that feature. If you encounter problem post it here and everyone
    will be willing to help you.

Similar Threads

  1. Need help in removing error in media player
    By mayank04 in forum AWT / Swing
    Replies: 1
    Last Post: 05-03-2011, 02:20 AM
  2. Java media player with subtitles with JVLC or JMF
    By foulkes in forum Advanced Java
    Replies: 0
    Last Post: 02-08-2011, 04:22 PM
  3. JMF: disable media info on a JMF Player
    By MarcioVilanova in forum Advanced Java
    Replies: 0
    Last Post: 08-11-2010, 08:16 PM
  4. javax.media.Player and JMenu problem
    By nowy in forum AWT / Swing
    Replies: 2
    Last Post: 11-10-2009, 11:49 AM
  5. Replies: 0
    Last Post: 11-04-2009, 09:09 PM

Posting Permissions

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