markku 0 Newbie Poster

Hello,

Well guys, I consider myself a beginner in Java generally and in JMF in particular, and actually I am student at the University and doing my project which creating Multi-video-Players (kindly check out my code in the bottom), so I have 6 different players and each one plays different video.

So the core of whole my project is to solve the video synchronization between those videos, one of the suggestion is to create window to control all the those videos together (I meant control them via creating 1 Seek Bar can control all the players together)

As a practical aspect, I actually would like to do the following:

1- Change the value of MAX_PLAYERS to be (private final int MAX_PLAYERS=5).
2- In this case I will get empty window in the coroner and there I would like to create 6 CheckBoxes and name them: (Player1 which present the Seek Bar of Player 1, Player2 which present the Seek Bar of Player 2,…, and last one name it All) and in the bottom of these 6 CheckBoxes I would like to create 1 Seek Bar (which is the Controller Seek Bar) and the idea behind that is when the user for instance ticked on CheckBox Player1 and Player4 then the Controller Seek Bar must turn to be the overall Seek Bar for both of those players together which means when I move it, it must move the frames inside those two players and so on, the same if the user ticked on All CheckBox the Controller Seek Bar must turn to be the overall Seek Bar for all those players together.

I know what I am saying is really hard and it has many problems like differences in times for those videos, maybe Player1 playing video clip 8 minutes and Player4 playing video clip 40 minutes, and how to manipulate and synchronize the situation in case if for example Player1 in the middle of the clip and Player4 just started.

Honestly speaking I don’t know how I am gonna to graduate with such kind of project, and truthfully I feel I am just dreaming and since 3 days I was just thinking and I wasn’t able to create any thing and I don’t know if my idea is applicable or not so I would really appreciate your helps, seriously I need your help so badly.

This is my code:

import java.awt.event.*;
import java.awt.*;
import javax.media.*;
import javax.swing.*;
 
 
 
public class PlayerTest extends JFrame implements
ActionListener,
ControllerListener
{
	//number of players on the same window
	private final int MAX_PLAYERS=6;
	//private final int MAX_PLAYERS=5;     in order to get 5 players and empty window in the corner
 
	//you can change the path
	private final String defultFile="file:/C:/1.mpg";
 
 
	private javax.media.Player player[]=new javax.media.Player[MAX_PLAYERS];
	private MediaLocator media[]= new MediaLocator[MAX_PLAYERS];
	private JPanel playerPanel[] = new JPanel[MAX_PLAYERS];
 
 
 
	private boolean realized;
	private Component display = null;
	String FileName = "";
 
 
	JFileChooser file = new JFileChooser();
 
	JButton browse[]=new JButton[MAX_PLAYERS];
 
	public PlayerTest() {
 
		super("Multi-Video-Player");
		setSize(800,600);
		JPanel mainPanel = new JPanel();
		JPanel submainPanel = new JPanel();
		mainPanel.setLayout(new GridLayout(3,2));
 
 
    	JPanel MenuPanel[]= new JPanel[MAX_PLAYERS];
 
 
		try{
			for (int i=0;i<MAX_PLAYERS;i++){
				realized=false;
				playerPanel[i]= new JPanel();
				MenuPanel[i]=new JPanel();
 
				media[i]=new MediaLocator(defultFile);
 
			browse[i]= new JButton("Browse");
 
 
 
 
			browse[i].addActionListener(this);
 
 
				playerPanel[i].setLayout(new BorderLayout());
				MenuPanel[i].setLayout(new BorderLayout());
			    player[i] = Manager.createPlayer(media[i]);
	            player[i].addControllerListener(this);
	            wrapRealize(player[i]);
	            player[i].prefetch();
	            if ((display = player[i].getVisualComponent()) != null )
	            playerPanel[i].add(display,BorderLayout.CENTER);
	            Component controller = player[i].getControlPanelComponent();
	            playerPanel[i].add(controller,BorderLayout.SOUTH);
		        MenuPanel[i].add(browse[i],BorderLayout.NORTH);
			    playerPanel[i].add(MenuPanel[i],BorderLayout.NORTH);
	            mainPanel.add(playerPanel[i]);
 
			}
		}catch (Exception ex){
            ex.printStackTrace();
			JOptionPane.showMessageDialog(null,"Invalid File Format","WARNING !!!",JOptionPane.WARNING_MESSAGE);
        }
        add(mainPanel);
		setVisible(true);
	}
 
	public synchronized void wrapRealize(javax.media.Player player) {
            player.realize();
            while(!realized) {
                try {
                    wait();
                }
                catch(InterruptedException interupt) {
                    interupt.printStackTrace();
					JOptionPane.showMessageDialog(null,"Invalid File Format","WARNING !!!",JOptionPane.WARNING_MESSAGE);
                }
            }
      }
 
 
public void actionPerformed (ActionEvent e)
 {
 
 	for (int i=0;i<MAX_PLAYERS;i++) {
 		if(e.getSource() == browse[i]) {
			try{
 
 
				if(file.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)  {
					System.out.println(file.getSelectedFile().getAbsolutePath());
					media[i]=new MediaLocator("file:"+file.getSelectedFile().getAbsolutePath());
 
 
					player[i].stop();
					playerPanel[i].remove(player[i].getVisualComponent());
					playerPanel[i].remove(player[i].getControlPanelComponent());
					player[i].close();
 
					player[i] = Manager.createPlayer(media[i]);
					player[i].addControllerListener(this);
					realized=false;
					wrapRealize(player[i]);
					player[i].prefetch();
					if ((display = player[i].getVisualComponent()) != null )
						playerPanel[i].add(display,BorderLayout.CENTER);
					Component controller = player[i].getControlPanelComponent();
					playerPanel[i].add(controller,BorderLayout.SOUTH);
					playerPanel[i].updateUI();
				}
 
	       }catch (Exception ex){
		        ex.printStackTrace();
		  		JOptionPane.showMessageDialog(null,"Invalid File Format","Browse",JOptionPane.WARNING_MESSAGE);
		   }
		   break;
		 }
	  }
 
 
 }
 
 
	public synchronized void controllerUpdate(ControllerEvent event ){
 
		if (event instanceof RealizeCompleteEvent){
			realized = true;
			notify();
        }
	}
 
    public static void main (String args[]) {
 
		PlayerTest app = new PlayerTest();
		app.setExtendedState(app.getExtendedState() | JFrame.MAXIMIZED_BOTH);
		app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}

regarding about my Project, honestly guys I'm a bit out of my profession (if I have one) on the details of JMF, I did tried one of the things mentioned in the JMF Guide (which is downloadable from here: http://java.sun.com/products/java-media/jmf/2.1.1/specdownload.html) Synchronizing multiple media streams section).) , named the addController method. I added the following piece of code at
the end of the loop in the PlayerTest constructor:
if(i != 0) {
player[0].addController(player);
}


This has the effect that for every player other than the first one, the
player is added to the list of the players controlled by the first one.
After this all the players can be started and paused by using the
controls of the first player. Unfortunately browsing button for a new video
seems to break the connection between players.

I guess we could create some logic to call addController and
removeController methods when checkboxes are selected or deselected, and
put the controller of one of the players in the corner of the screen,
but I don't know if that will work past all the difficulties.

Therefore, I would like to ask a help from you guys to help me in my project and hopefully we will manage to finish it and upload the code in the forum to exchange the knowledge, I really need urgent help and truthfully I am running out of time, and I would appreciate that for you too much.


P.S any feedback from anyone will be greatly appreciated

I hope to hear from you soon, and I really need your help so badly,


Kind Regards,
Markku

<email snipped>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.