I use network for transfer data.
I refered this site.
I prepared ParcelFileDescriptor and socket.
ParcelFileDescriptor pfd = null; Socket socket = null;I set for network setting.
192.168.1.2 is my pc ip address.
String hostname = "192.168.1.2"; int port = 5000;I try to create socket
try { socket = new Socket(InetAddress.getByName(hostname), port); pfd = ParcelFileDescriptor.fromSocket(socket); } catch (UnknownHostException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }I try to set ParcelFileDescriptor to MediaRecorder.
_mediarecorder = new MediaRecorder(); _mediarecorder.setOutputFile(pfd.getFileDescriptor());Android source code is here.
Next Server side program. this program do in my pc(192.168.1.2).
and this is java language.
I create server socket. port number need to be same between client and server.
ServerSocket svsock = new ServerSocket(5000);I prepare file.
outFile = new FileWriter("xyz" + i + ".mp4");I wait client(Android) connecting by acccept.
Socket sock = svsock.accept();If client(Android) connected, I use accept socket sock.
sock.getInputStream()I prepare BufferedReader and BufferedWriter, and I write received data to the file.
BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream())); BufferedWriter wt = new BufferedWriter(outFile); while(sock.isConnected()) { int line = in.read(); if (line == -1) { break; } wt.write(line); }If client(Android) connecting finished, I close.
outFile.close(); sock.close();server sid source code is here.
IMPORTANT, First server side do, Next Client(Android) do.
server side recive file analysis.
Please suggest your android issue by twitter or mail, I would try to clear up your issue.
0 件のコメント:
コメントを投稿