i have a classical server client tcp socket system to send messages from client to a server. That works quiet fine. Now I am trying to play a sound remote. The client should send the path to the sound. It is /mnt/sdcard/Music/sound.mp3
This is what it sends to the server.
The server knows the client IP. Maybe the IP string looks like /192.168.1.2
The server should interprete it and start the sound by streaming.
private void playSound (String soundFileName) {
Uri myUri1 = Uri.parse("file:/" + _clientIP + soundFileName);
_txtHint.setText(myUri1.toString());
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mPlayer.setDataSource(getApplicationContext(), myUri1);
} catch (IllegalArgumentException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
try {
mPlayer.prepare();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "MISE: You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "MIOE: You might not set the URI correctly!", Toast.LENGTH_LONG).show();
}
mPlayer.start();
}
If I take a simple http URI it works very well (i.e. http://test.com/sound.mp3). The sound will be played. Now I am trying to play the sound the client sends to the server. But the code breaks with an IOException ("Prepared failed: status 0x1") at mPlayer.prepare();
I believe the URI is wrong. I tried several ways (rtsp://IP:port/path
, rtsp://IP/path
, same with file://
and http://
). But I do not find the right one. Maybe I miss a thing? Do the server have permission to access the clients sound? If not, how do I give it to the server?
Thanks for your help! Greets, S-Man
Edit1: ServerSocket
try {
_serverSocket = new ServerSocket(SocketServerPORT);
while (true) {
socket = _serverSocket.accept();
dataInputStream = new DataInputStream(
socket.getInputStream());
dataOutputStream = new DataOutputStream(
socket.getOutputStream());
_message = dataInputStream.readUTF();
_clientIP = socket.getInetAddress().toString();
Server.this.runOnUiThread(new Runnable() {
@Override
public void run() {
//Here the Sound should be played.
Server.this.playSound(_message);
}
});
dataOutputStream.writeUTF(_message);
}
} catch (IOException e) {...