1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| ExecutorService executorService = Executors.newFixedThreadPool(2);
executorService.execute(new Runnable() {
public void run() {
client = new Socket(IP_SERVER, PORT_SERVER); // Creating the server socket.
if (client != null) {
// Receive video
InputStream in = client.getInputStream();
OutputStream out[] = new OutputStream[1];
// Store on device
out[0] = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Movies/chrono2.mp4");
byte buf[] = new byte[1024];
int n;
while ((n = in.read(buf)) != -1) {
out[0].write(buf, 0, n);
//Adding last in the queue
//Log.d("byte" , "" + out);
}
in.close();
out[0].close();
client.close();
}
});
executorService.execute(new Runnable() {
public void run() {
MediaPlayer mp = new MediaPlayer();
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
mp.setDataSource(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Movies/chrono2.mp4");
mp.prepare();
mp.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}); |
Partager