Phaelax 52 Practically a Posting Shark

I'm using JMF to transmit webcam data to another pc. I'm not using another thread yet, but I'm assuming that ServerSocket.accept() will hault the program until something attempts to connect to it? It seems to connect ok, but I dont get any video, just a black screen. So maybe the problem is in the JMF? ideas?


server, sends video data:

import javax.media.bean.playerbean.MediaPlayer;
import java.awt.BorderLayout;
import javax.swing.*;
import java.awt.event.*;
import javax.media.*;
import java.awt.Component;
import java.net.*;
import java.io.ObjectOutputStream;
import java.io.BufferedOutputStream;

public class CamServer extends JFrame
{
	private MediaPlayer mp = null;
	private ServerSocket server = null;
	
	
	public CamServer()
	{
		mp = new MediaPlayer();
		mp.setMediaLocation("vfw://0");
		mp.setControlPanelVisible(true);
		mp.start();
		mp.realize();
		mp.setFixedAspectRatio(true);
		mp.setPopupActive(true);
		
		final JPanel camPanel = new JPanel();
		
		
		class MyControllerListener implements ControllerListener
		{
			public void controllerUpdate(ControllerEvent e)
			{
				if(e instanceof RealizeCompleteEvent)
				{
					camPanel.add(mp.getVisualComponent());
					
					try
					{
						server = new ServerSocket(3190);
						Socket s = server.accept();
						ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(s.getOutputStream()));
						mp.writeExternal(out);
						System.out.println(s);
					}
					catch(Exception ex)
					{
						System.out.println("error: "+ex);
					}
				}//if instanceof
			}//method
		}//end class
		
		mp.addControllerListener(new MyControllerListener());
		
		class Listener implements ActionListener
		{
			public void actionPerformed(ActionEvent e)
			{
				mp.stopAndDeallocate();
			}
		}
		JButton closeButton = new JButton("Close");
		closeButton.addActionListener(new Listener());
		
		this.getContentPane().setLayout(new BorderLayout());
		this.getContentPane().add(camPanel, BorderLayout.CENTER); 
		//this.getContentPane().add(mp.getControlPanelComponent(), BorderLayout.NORTH);
		this.getContentPane().add(closeButton, BorderLayout.SOUTH);
	}//end constructor
 

	public static void main()
	{
		CamServer frame = new CamServer();
		frame.show();
	}
	
}

socket, gets the video data

import javax.media.bean.playerbean.MediaPlayer;
import javax.media.*;
import java.net.Socket;
import java.io.ObjectInputStream;
import javax.swing.*;
import java.awt.BorderLayout;

public class ReceiveCam extends JFrame implements Runnable
{
	private MediaPlayer mp = new MediaPlayer();
	private Socket connection = null;
	private ObjectInputStream in = null;
	
	public ReceiveCam()
	{
		super("Receiving...");
		final JPanel camPanel = new JPanel();
		try
		{
			connection = new Socket("192.168.2.191", 3190);
			
			System.out.println(connection.isConnected());
				
				
				
			connection.setSoTimeout(10000);
			in = new ObjectInputStream(connection.getInputStream());
			if (in != null)
			{
				mp.readExternal(in);
				mp.start();
				mp.realize();
				mp.setPopupActive(true);
			}
			else
				System.out.println("No input stream");
		}
		catch(Exception e)
		{
		}
		
		class MyControllerListener implements ControllerListener
		{
			public void controllerUpdate(ControllerEvent e)
			{
				if (e instanceof RealizeCompleteEvent)
				{
					camPanel.add(mp.getVisualComponent());
					System.out.println("event: "+e);
				}
			}
		}
		
		
		this.getContentPane().setLayout(new BorderLayout());
		this.getContentPane().add(camPanel, BorderLayout.CENTER);
		
	}
	public void run()
	{
	}

	public static void main()
	{
		ReceiveCam frame = new ReceiveCam();
		frame.show();
	}
}
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.