I am trying to get a video stream from point A (2.1 Android phone) to point B (my server) in real time. How can i do this? Following are my attempts (a little long but short!)
The goal is to get hourly video recorded from the phone to the server without pausing / stopping the stream. a delay of up to several minutes is not a problem. I tried three approaches
- a FileInputStream stream that reads destination video from a FileDescriptor
- call MediaRecoder.setOutputFile on FD of the 'sender' connector. this connector connects to LocalSocketServer, the destination of which is the receiver socket.
- open the socket for my server and providing setOutputFile your FD
unfortunately, both attempts failed.
- Logs only 24 bytes when i call FileInputStream.available (), and the actual number of bytes after I call Recorder.stop ()
gives me this completely useless stacktrace
ERROR / AndroidRuntime (18532): caused by: java.lang.RuntimeException: failed to start. ERROR / AndroidRuntime (18532): on android.media.MediaRecorder.start (native method) ERROR / AndroidRuntime (18532): in com.example.demovideo.DemoVideo.initializeCamera (...) ...
same error 2
code fragments (parts skipped)
one)
fileOut = new FileOutputStream(pathToFile); ... recorder.setOutputFile(fileOut.getFD()); recorder.prepare() recorder.start() // in an Async Thread fileIn = FileInputStream(fileOut.getFD); while (recording) { fos.flush(); Log.w("---", "bytesAvailable: " + fileIn.available()); //always returns 24 Thread.sleep(1000); }
2)
// in a Thread server = new LocalServerSocket(SOCKET_ADDRESS); while (true){ receiver = server.accept(); if (receiver != null){ InputStream input = receiver.getInputStream(); ... // processing would go here } } sender = new LocalSocket(); sender.connect(new LocalSocketAddress(SOCKET_ADDRESS)); recorder.setOutputFile(sender.getFileDescriptor()); ... recorder.prepare(); recorder.start(); // <- error
- correctly saves intact video to sd
- works if i use setOutputFile (pathToFile). sockets also work when I run
sender.getOutputStream().write(message.getBytes());
java android video-streaming streaming mediarecorder
ebaum
source share