Guest User

Untitled

a guest
Nov 29th, 2019
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import sun.audio.AudioPlayer;
  2. import sun.audio.AudioStream;
  3.  
  4. import java.io.*;
  5. import java.net.URL;
  6. import java.net.URLConnection;
  7. public class Main {
  8.  
  9.  
  10. public static void main(String[] args) throws IOException {
  11. URLConnection conn = new URL("http://streams.ilovemusic.de/iloveradio6.mp3").openConnection();
  12. InputStream is = conn.getInputStream();
  13. OutputStream out = new FileOutputStream(new File("C:/Users/rasah_s2z0ncs/Desktop/CwBw/abc.mp3"));
  14. byte[] buffer = new byte[4096];
  15. int len;
  16.  
  17.  
  18.  
  19. Thread t = new AudioThread();
  20. t.start();
  21. while ((len =is.read(buffer)) > 0){
  22.  
  23.  
  24.  
  25. out.write(buffer);
  26. System.out.println(len);
  27.  
  28.  
  29. }
  30.  
  31. }
  32.  
  33.  
  34. private static class AudioThread extends Thread {
  35. @Override
  36. public void run(){
  37. try {
  38. sleep(2000);
  39. AudioPlayer.player.start(new AudioStream(new FileInputStream("C:/Users/rasah_s2z0ncs/Desktop/CwBw/abc.mp3")));
  40. } catch (InterruptedException | IOException e) {
  41. e.printStackTrace();
  42. }
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment