java client server program for playing video file(stored in folder in the same workspace) using swings

java client server program for playing video file(stored in folder in the same workspace) using swings

Hello friends this is RAGHAVENDRA, I am doing a client server program to play a video file, when I run both client and server programs I still not getting any outputs and even I am not getting ERRORS please help me to get rid of this problem.

client.java

  import java.awt.Color;
  import java.awt.Component;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.io.File;
  import java.io.IOException;
  import java.io.ObjectOutputStream;
  import java.net.MalformedURLException;
  import java.net.Socket;
  import java.net.UnknownHostException;
  import javax.media.CannotRealizeException;
  import javax.media.Manager;
  import javax.media.NoPlayerException;
  import javax.media.Player;
  import javax.swing.BorderFactory;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JTextField;


  public class client extends JFrame
  {
clientreceive cr;
JPanel p;

public void init()
{
    clientreceive cr = new clientreceive();
}

public client()
{
    getContentPane().setLayout(null);
    getContentPane().setBackground(Color.WHITE);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel l = new JLabel("enter file name");
    l.setBounds(50, 30, 100, 50);
    getContentPane().add(l);

    final JTextField t = new JTextField();
    t.setBounds(160, 45, 100, 30);
    getContentPane().add(t);

    JButton b = new JButton("go");
    b.setBounds(145, 100, 50, 30);
    getContentPane().add(b);

    b.addActionListener(new ActionListener()
    {
        public void actionPerformed(ActionEvent arg0)
        {
            sendREQ(t.getText());

        }
    });

    JButton b1 = new JButton("play");
    b1.setBounds(145, 130, 70, 30);
    getContentPane().add(b1);

    b1.addActionListener(new ActionListener()
    {
        public void actionPerformed(ActionEvent arg0)
        {
            mediaPlayer(cr.lrecFile.getAbsolutePath(),p);       
        }
    });

      JPanel p = new JPanel();
      p.setBorder(BorderFactory.createTitledBorder("Videoplayer"));
      p.setBounds(125, 200, 300, 300);
      getContentPane().add(p);

    setSize(600,600);
    setVisible(true);
  }

    protected void mediaPlayer(final String Path, final JPanel panel)
   {
    new Thread() {
        public void run() {
            try {
                Player p = Manager.createRealizedPlayer(new File  (Path)
                        .toURL());
                Component ctrlpanel = p.getControlPanelComponent();
                Component player = p.getVisualComponent();
                player.setBounds(10, 20, 300, 170);
                ctrlpanel.setBounds(10, 191, 300, 20);
                panel.add(player);

                panel.add(ctrlpanel);
                panel.repaint();
                p.start();
                System.out.println(" Player Started");
            } catch (NoPlayerException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (CannotRealizeException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }.start();

}

protected void sendREQ(String text)
{
    try {
        Socket soc = new Socket("localhost", 4576);
        ObjectOutputStream oos = new ObjectOutputStream(
                soc.getOutputStream());
        oos.writeObject("REQ");
        oos.writeObject(text);

        System.out.println(text);

    }
    catch (UnknownHostException e)
    {

        e.printStackTrace();
    }
    catch (IOException e)
    {

        e.printStackTrace();
    }

}

public static void main(String args[])
{
    new client();
}

}

 clientreceive.java

 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.ObjectInputStream;
 import java.net.ServerSocket;
 import java.net.Socket;
 import javax.swing.JOptionPane;


 public class clientreceive
 {
File lrecFile;
Socket soc;
ServerSocket serSoc;
ObjectInputStream ois;

clientreceive()
{
    receive();
}

private void receive()
{
      try
      {
          System.out.println("Inside clientreceive");
          serSoc = new ServerSocket(4576);

          while (true)
            {
                soc = serSoc.accept();
                ois = new ObjectInputStream(soc.getInputStream());
                String str = (String) ois.readObject();
                checkStatus(str);
            }
      }
      catch (Exception e)
      {
          e.printStackTrace();
      }

 }

  private void checkStatus(String str)
  {
    try
    {
        if (str.equals("REP"))
        {
            byte[] file = (byte[]) ois.readObject();
            String filename = (String) ois.readObject();

            String scn = (String) ois.readObject();

            lrecFile = new File("RecFiles/" + scn + "" + filename);

            FileOutputStream fos = new FileOutputStream(lrecFile);
            fos.write(file);
            fos.close();



            JOptionPane.showMessageDialog(null, "Last Received File is:"
                    + lrecFile.getAbsolutePath());

        }
        else if (str.equals("NoFile")) {
            JOptionPane.showMessageDialog(null,
                    "The User Requested File Not Found.");

        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

}

}

     server.java

     import java.io.File;
     import java.io.FileInputStream;
     import java.io.ObjectInputStream;
     import java.io.ObjectOutputStream;
     import java.net.ServerSocket;
     import java.net.Socket;
     import javax.swing.JOptionPane;


     public class server
     {

  private Socket soc;
  private ServerSocket serSoc;
  private ObjectInputStream ois;

  server()
 {
    try {
        serSoc = new ServerSocket(4576);
        while (true)
        {
            soc = serSoc.accept();
            ois = new ObjectInputStream(soc.getInputStream());
            String str = (String) ois.readObject();
            checkStatus(str);
        }
       } 
    catch (Exception e)
    {
        e.printStackTrace();
    }
  }

   private void checkStatus(String str)
  {
    try
    {
        if (str.equals("REQ"))
        {
            String file = (String) ois.readObject();
            System.out.println("inside ck status");
            process(file);
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

  }

   private void process(String file)
  {
    try
    {
        System.out.println("inside process");
        File file2 = new File("ServerDB/" + file);

        if (file2.exists() == false) 
        {
            JOptionPane.showMessageDialog(null,
                    "The User Requested File Not Found. ");
        }

        FileInputStream fis = new FileInputStream(file2);
        byte[] b = new byte[fis.available()];
        fis.read(b);
        fis.close();

        Socket socket = new Socket("localhost",4576);
        ObjectOutputStream oos = new ObjectOutputStream(
                socket.getOutputStream());
        oos.writeObject("REP");
        oos.writeObject(b);
        oos.writeObject(file2.getName());

     }
      catch (Exception e)
     {
        e.printStackTrace();
    }

  }

     public static void main(String args[])
   {
    new server();
    }

}

View Answers









Related Tutorials/Questions & Answers:
java client server program for playing video file(stored in folder in the same workspace) using swings
java client server program for playing video file(stored in folder in the same workspace) using swings  Hello friends this is RAGHAVENDRA, I am doing a client server program to play a video file, when I run both client and server
java client server program for playing video file(stored in folder in the same workspace) using swings
java client server program for playing video file(stored in folder in the same workspace) using swings  Hello friends this is RAGHAVENDRA, I am doing a client server program to play a video file, when I run both client and server
Advertisements
java client server program for playing video file(stored in folder in the same workspace) using swings
java client server program for playing video file(stored in folder in the same workspace) using swings  Hello friends this is RAGHAVENDRA, I am doing a client server program to play a video file, when I run both client and server
java client server program for playing video file(stored in folder in the same workspace) using swings
java client server program for playing video file(stored in folder in the same workspace) using swings  Hello friends this is RAGHAVENDRA, I am doing a client server program to play a video file, when I run both client and server
Playing mp3 file in Java...
Playing mp3 file in Java...  I created frame with play and stop buttons and added separate ActionListener to those buttons but i can't stop the music while playing
video playing
video playing  please give me a sample code to play uploaded videos i have alredy uploaded videos but when i try to play it using html5 nothing happens i need youtube like video playing . please somebody help me
want a program for date picker by using java swings
want a program for date picker by using java swings  to write a program for the date picker by using java swings.any one please help me by providing the code to this java date picker by using the java swings.previously a program
Video streaming using java
have to stream the video in the server side and send that to the client side.(Like youtube i.e no video url has to be used in client side). I didn't have any...Video streaming using java  I want to create a website based on video
java code using swings
java code using swings  code that should be able to enter data of student details using all swings into the access database using jdbc connectivity
Video Tutorial of reading file in Java
file line by line in Java using Eclipse Project: In this video...Java Video Tutorial: Learn how you can read a big text file in Java? Java... file in Java How to Read Excel file Using Java
playing an audio file
playing an audio file  In playing an audio file we have to take one... path   Please visit the following link: http://www.roseindia.net/java/example/java/applet/PlaySoundApplet.shtml
proxy server and client using java - Java Beginners
proxy server and client using java  how to write program in java for proxy server and client
edit the flash video file using html5
edit the flash video file using html5  hi iam vivek i have a flash file i want to edit it with html5 please reply
Record and Save Video using Java
Record and Save Video using Java  How to record video(webcam) and save it using Java.?? Its really urgent
File transfer from client to server - Java Beginners
File transfer from client to server  hi,, I've been trying to make an application where the user select a file using JFileChooser and then the program directly send it to the server using client/server sockets, I've tried
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?  write a program in java to read a text file and write the output to an excel file using filereader and filewriter
Java Program to insert a row in the same sheet of excel file
Java Program to insert a row in the same sheet of excel file  Java program to insert a row in the same sheet of excel file using poi package in java
Image Movement using Swings
Image Movement using Swings  How to move image using Swings
upload video using php
upload video using php  How to upload a video on MYSQL Server using PHP Code..? Can any one provide me an example
An application using swings and vector methods
An application using swings and vector methods   Hi, I want an application in Java swings which uses good selection of Vectors methods
JMF: How trigger event when player reaches certain time playing a video?
JMF: How trigger event when player reaches certain time playing a video?  How to code in Java (with Java Media Framework): When the player reaches a certain time playing a video clip (for example, reaching 3.124 minutes
Server calling of .exe file in the client
Server calling of .exe file in the client   I have a requirement with java webapplication. We are using jboss as appserver on Linux machine. How can I call a .exe file from client machine? I want to run .exe from webpage like
Image is in same folder where the java file is located - Swing AWT
Image is in same folder where the java file is located  dear sir It is there in the same folder..means the photograph.jpg file is created in the same folder where my java file is present... wat I should do sir
A Java Program by using JSP
A Java Program by using JSP  how to draw lines by using JSP plz show me the solution by using program
RARP program using java
RARP program using java   hai, how to implement the RARP concept using java
File format validation and text field validation in java swings
File format validation and text field validation in java swings   i am reading a jpg image file throuh jfilechooser in java swings,when we press... 'please select jpg file only' plz give me the code in swings. Please
making of dynamic textfields using swings
making of dynamic textfields using swings  How to make dynamic textfields using java swings
need to open a file that is in server using jsp
need to open a file that is in server using jsp   im doing a web... a pdf files and stored its path on the database.what i want is when i search... is just want to open a pdf in jsp.is it possible to open sever file from jsp.Plz
Frames from a yuv video file
Frames from a yuv video file  hi, please help me with the java code for extracting frames of yuv video file. After extraction the images should be stored in jpeg format. Please help me
Frames from a yuv video file
Frames from a yuv video file  hi, please help me with the java code for extracting frames of yuv video file. After extraction the images should be stored in jpeg format. Please help me
video uploading using jsp
video uploading using jsp  how to upload a videos in web page using jsp   Hi, You can upload your video with the help of JSP file upload code. Once file is upload you can play using any video player. Get the code
Video Tutorial: How to check if a folder exists in Java through a source code
facilities. Here is the video tutorial of "How to check if a folder exists in Java...How to check if a folder exists in Java through a source code Java is an all... famous programming languages in vogue, especially for client server web execution
Create text file at client's directory from server.
Create text file at client's directory from server.  Need java code to create text file at client's directory from server..... Please Help
How to Read file line by line in Java program
by line in Java. But there are various ways that can help read a larger file...? that includes a text. Now first thing a program has to do is to find the file... of read file line by line in Java is printed on console.ADS_TO_REPLACE_5
how to connect client to server using Sockets
how to connect client to server using Sockets  how to connect client to server using Sockets
another frame by using awt or swings
another frame by using awt or swings  how to connect one frame to another frame by using awt or swings
how to store data in table using swings - Java Beginners
how to store data in table using swings  Hi, I am doing a project in which i need to store some data in the table using swings.......Iam using... , whether do i have any option in swings to increase my output look (my target
Program to read a dynamic file content - Java Beginners
the database. Im using MySql Database and a standalone java program. I...Program to read a dynamic file content  Hi, In a single folder daily date wise the datas will be stored automatically in the .txt format
video uploading using jsp
video uploading using jsp  this is the code i hv written...++,'\\'); } File outfile = new File(sb+"videos\\"+video... html file <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN
virtual onscreen keyboard project using java and swings - Swing AWT
virtual onscreen keyboard project using java and swings  Im doing virtual on screen keyboard as my project. i didnt get the method to performthe backspace and space operation using swings in java.can please help me  Hi
how can i draw a table using applet or swings - Java Beginners
how can i draw a table using applet or swings  Hi RoseIndia, Actually, I was trying for creating a table using applet or swings.......... My task is create a table and enter the integer values during run time......I have
how to delete a jar file from mobile by using j2me program.
how to delete a jar file from mobile by using j2me program.  When i'll update a new version jar in mobile. Then i want to delete that old jar which is previously present in mobile. How to do
Read Video File
Read Video File  how to read a video file, after that i want to encrypt and decrypt it. please help me and if u can send me some hint or source code on [email protected] Thanks & Regards Swarit Agarwal
Program to count the number of unique words in a file using HashMap
Program to count the number of unique words in a file using HashMap  import java.io.File; import java.io.FileNotFoundException; import java.util....[]) throws FileNotFoundException { File f = new File("C:/547647/word
java program using control statements...
java program using control statements...  public class ControlStatements { public static void main(String args[]){ int x=10; if(x==0...("It is negative number"); }}} in this program what and where it is error and why
Java Program Qns using BlueJ
Java Program Qns using BlueJ  Write a program that accepts one...), showing the carry, the quotient and the remainder. The program should output... are 158 and 7, the program should output: 1 1 7) 1 5 8 0 2 2 R4 If the two
FTP Server : Upload file
This tutorial contains description of file uploading to the FTP server using java
FTP Server : Download file
This tutorial contains description of file downloading from the FTP server using java
Search file on Ftp Server
In this section, you will learn how to check existence of a file on the server by using java
How can i draw a line using java swings
How can i draw a line using java swings  Sir my program contains different components i am using JFrame. I want to draw a straight line between components(Jtextfeilds, Jlabels).So could you help me for it. Thank You

Ads