Hi all,
I have two simple programmes, one server and one mediaplayer client,
both at localhost. The problem is I can send byte/text through the
socket, but when I try to send a video file, from the sdcard to the
socket, the client side mediaplayer cannot play it. Anyone know how to
solve this problem? What I send is just first few bytes of the video.
Do I need add some packet headers?Thanks.
Server:
Socket client=serversocket.accept();
System.out.println("accept");
//Receive client message.
BufferedReader in=new BufferedReader(new
InputStreamReader(client.getInputStream()));
String str=in.readLine();
System.out.println("read:"+str);
//Send message to client.
//PrintWriter out=new PrintWriter(new BufferedWriter(new
OutputStreamWriter(client.getOutputStream())),true);
//out.println("server message");
FileInputStream fis=new FileInputStream("/sdcard/
toystory3.3gp");
byte buffer[]=new byte[2000];
fis.read(buffer,0,20);
DataOutputStream out=new
DataOutputStream(client.getOutputStream());
out.write(buffer,0,20);
in.close();
out.close();
client.close();
System.out.println("close");
Client:
Socket socket=new Socket("127.0.0.1",4444);
String message="Initial"+"\r\n";
//Send message to server.
PrintWriter out=new PrintWriter(new BufferedWriter(new
OutputStreamWriter(socket.getOutputStream())),true);
out.println(message);
//Receive message from server.
//BufferedReader br=new BufferedReader(new
InputStreamReader(socket.getInputStream()));
//String msg=br.readLine();
ParcelFileDescriptor pfd=ParcelFileDescriptor.fromSocket(socket);
MediaPlayer m=new MediaPlayer();
m.setDataSource(pfd.getFileDescriptor());
m.prepare();
m.start();
/*if(msg!=null)
{
System.out.println("Data received.");
System.out.println(msg);
}
else
{
System.out.println("Data not received.");
}*/
out.close();
br.close();
socket.close();
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en