Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: media in InternalJFrame

  1. #1
    jumpman8947 is offline Member
    Join Date
    Feb 2013
    Posts
    38
    Rep Power
    0

    Default media in InternalJFrame

    I have created a frame in which there is an internal jframe showing inside it. What i want to do is use the JMF video playback displaying in the internal frame not the main frame. Currently when i run the program the video plays over the whole frame. all i want it to do is play within the internalJFrame. And with me testing out the code before i added video both frames display so i know that showing both frames isn't the problem. the problem is showing the video inside the internal frame.
    Java Code:
    import javax.media.*;
    import javax.swing.*;
    import java.awt.*;
    import java.net.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.io.File;
    import java.net.MalformedURLException;
    import java.net.URL;
    
    public class Internal extends JFrame
    {
    	private JPanel mainPanel;
    	Player _player;
    	JFileChooser fileChooser;
    
    	public Internal()
    	{
    
    		mainPanel = new JPanel();
    		getContentPane().add(mainPanel);
    		mainPanel.setLayout(null);
    
    		addWindowListener( new WindowAdapter(){
    			public void windowClosing( WindowEvent e)
    			{
    				_player.stop();
    				_player.deallocate();
    				_player.close();
    				System.exit(0);
    			}
    		});
    
    
    
    
    
    		JInternalFrame f1 = new JInternalFrame("Preview",
    												true,
    												true,
    												true,
    												true);
    		f1.setBounds(810,20,500,370);
    
    		JPanel panel =(JPanel)getContentPane();
    		panel.setLayout(new BorderLayout());
    		String mediaFile = "DD.avi";
    		try{
    			//Media Code
    		}
    		catch (Exception e) {
    			System.err.println("Got exception" + e );
    
    		//getContentPane().add(panel);
    
    		f1.getContentPane().add(panel);
    
    		mainPanel.add(f1);
    		f1.setVisible(true);
    
    		setTitle("Internal Demo");
    		setLocationRelativeTo(null);
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    		setVisible(true);
    		this.setExtendedState(Frame.MAXIMIZED_BOTH);
    	}
    }
    	public static void main(String[] args)
    	{
    		Internal in = new Internal();
    		in.show();
    	}
    
    }

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

    Default Re: media in InternalJFrame

    1. JInternalFrame is designed to be displayed in a JDesktopPane. Not in a JPanel.
    2. Please learn and respect the Code Conventions for the Java Programming Language: Contents

    Since your code doesn't reveal what visual component is used for video playback, any help would have to be based on guesswork.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    jumpman8947 is offline Member
    Join Date
    Feb 2013
    Posts
    38
    Rep Power
    0

    Default Re: media in InternalJFrame

    well i added a jdesktoppane and i get the same problem
    Java Code:
    import javax.swing.*;
    import javax.media.*;
    import java.awt.*;
    import java.net.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.io.File;
    import java.net.MalformedURLException;
    import java.net.URL;
    
    public class DeskTest extends JFrame {
    	Player _player;
    
      DeskTest() {
    
       addWindowListener( new WindowAdapter(){
       					public void windowClosing( WindowEvent e)
       					{
       						_player.stop();
       						_player.deallocate();
       						_player.close();
       						System.exit(0);
       					}
    				});
    
    
       JFrame frame = new JFrame();
        JDesktopPane desk = new JDesktopPane();
        JInternalFrame inFrame = new JInternalFrame("Internal",
        											true,
        											true,
        											true,
        											true);
        inFrame.setSize(300,300);
        //JButton myButton = new JButton("1");
    
      //  inFrame.add(myButton);
    
    
      JPanel panel =(JPanel)getContentPane();
      		panel.setLayout(new BorderLayout());
      		String mediaFile = "DD.avi";
      		try{
      			MediaLocator mlr = new MediaLocator("file:" + mediaFile );
      			_player = Manager.createRealizedPlayer(mlr);
      			if (_player.getVisualComponent() !=null)
      			panel.add("Center", _player.getVisualComponent());
      			if(_player.getControlPanelComponent() !=null)
      			panel.add("South", _player.getControlPanelComponent());
      			_player.start();
      		}
      		catch (Exception e) {
      			System.err.println("Got exception" + e );
    
      	inFrame.getContentPane().add(panel);
    
    
    
        inFrame.pack();
        inFrame.setVisible(true);
    
        desk.add(inFrame);
        frame.add(desk);
    
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
        //this.setExtendedState(Frame.MAXIMIZED_BOTH);
        frame.setSize(1000,1000);
      }
    }
    
      public static void main(String[] args) {
        DeskTest test = new DeskTest();
        test.show();
      }
    }

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

    Default Re: media in InternalJFrame

    Looking at the JMF API, Player#getVisualComponent() returns a java.awt.Component. The API does not make any guarantees that this derives from JComponent, and I suspect it does not.

    The issue may be related to Mixing Heavyweight and Lightweight Components although with the latest Java versions that isn't supposed to create any problems.

    You might be better off porting your application to JavaFX 2 and using a MediaView, but check the file type compatibility first.

    db
    gimbal2 likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,050
    Rep Power
    6

    Default Re: media in InternalJFrame

    Yes but JMF has been abandoned for longer than the heavyweight/lightweight fixes I believe, so whatever component it returns may still be broken.

    Which is one more reason to not use JMF. Its a red headed stepchild, better go for one of the alternatives that people do care about. JavaFX 2 is currently a preferable option. You can even embed JavaFX into Swing I believe, so you could hack its video playing capabilities into an existing Swing application.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default Re: media in InternalJFrame

    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. video media
    By jumpman8947 in forum New To Java
    Replies: 0
    Last Post: 08-26-2013, 07:55 AM
  2. How can sent image with media
    By raj.mscking@gmail.com in forum New To Java
    Replies: 1
    Last Post: 02-01-2012, 09:09 PM
  3. media player
    By rithish in forum AWT / Swing
    Replies: 2
    Last Post: 05-26-2011, 09:42 AM
  4. Media Keys
    By tikigod in forum New To Java
    Replies: 0
    Last Post: 01-28-2009, 11:30 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
  •