androidvideostream

Is it possible to play a mp4 Video file while downloading it throuh a LAN connection?


My client wish to stream video files from his camera storage to his android phone using only LAN connection. Is this possible? For the moment, the only thing that I can do is play a video from the storage of the phone and stream HTTP or RTSP streams video, but is it possible to stream a video file while sending it through LAN?

public class Client extends Activity {

    private Socket client;
     private FileInputStream fileInputStream;
     private BufferedInputStream bufferedInputStream;
     private OutputStream outputStream;
     private Button button;
     private TextView text;
     
     @Override
     public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
     
      button = (Button) findViewById(R.id.button1);   
      text = (TextView) findViewById(R.id.textView1);   
     
      //Button press event listener
      button.setOnClickListener(new View.OnClickListener() {
     
       public void onClick(View v) {
     
         

     
    File file = new File("/storage/emulated/BaseAhri.jpg"); 
     
    try {
      
     client = new Socket("10.0.2.2", 4444);
      
     byte[] mybytearray = new byte[(int) file.length()]; 
 
     fileInputStream = new FileInputStream(file);
     bufferedInputStream = new BufferedInputStream(fileInputStream); 
 
     bufferedInputStream.read(mybytearray, 0, mybytearray.length); 
 
     outputStream = client.getOutputStream();
 
     outputStream.write(mybytearray, 0, mybytearray.length);
     outputStream.flush();
     bufferedInputStream.close();
     outputStream.close();
           client.close();
            
           text.setText("File Sent");
      
      
    } catch (UnknownHostException e) {
     e.printStackTrace();
    } catch (IOException e) {
     e.printStackTrace();
    }

Server Side


    private static ServerSocket serverSocket;
    private static Socket clientSocket;
    private static InputStream inputStream;
    private static FileOutputStream fileOutputStream;
    private static BufferedOutputStream bufferedOutputStream;
    private static int filesize = 10000000; 
    private static int bytesRead;
    private static int current = 0;
 
    public static void main(String[] args) throws IOException {
 
 
        serverSocket = new ServerSocket(4444); 
 
        System.out.println("Server started. Listening to the port 4444");
 
 
        clientSocket = serverSocket.accept();
 
 
        byte[] mybytearray = new byte[filesize];  
 
        inputStream = clientSocket.getInputStream();
        fileOutputStream = new FileOutputStream("/sdcard/DCIM/Camera/BaseAhri.jpg");
        bufferedOutputStream = new BufferedOutputStream(fileOutputStream);});
       System.out.println("Receiving...");
 
        
        bytesRead = inputStream.read(mybytearray, 0, mybytearray.length);
        current = bytesRead;
 
        do {
            bytesRead = inputStream.read(mybytearray, current, (mybytearray.length - current));
            if (bytesRead >= 0) {
                current += bytesRead;
            }
        } while (bytesRead > -1);
 
 
        bufferedOutputStream.write(mybytearray, 0, current);
        bufferedOutputStream.flush();
        bufferedOutputStream.close();
        inputStream.close();
        clientSocket.close();
        serverSocket.close();
 
        System.out.println("Sever recieved the file");
 
    }

Error Server Side

[2014-01-22 15:20:15 - AndroidSocketSERVER] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.javacodegeeks.android.androidsocketserver/.Server }

[2014-01-22 15:20:15 - AndroidSocketSERVER] ActivityManager: Error type 3

[2014-01-22 15:20:15 - AndroidSocketSERVER] ActivityManager: Error: Activity class {com.javacodegeeks.android.androidsocketserver/com.javacodegeeks.android.androidsocketserver.Server} does not exist.

And in the client side it crashes after I send. Not sure if this is an error, since my server has a problem.


Solution

  • Actually it is. You will need to build your own socket server in app and play video from it. Then you will have control over byte input stream and save dowloaded part to file while same part will go to mediaplayer