Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sun.audio.AudioPlayer;
- import sun.audio.AudioStream;
- import java.io.*;
- import java.net.URL;
- import java.net.URLConnection;
- public class Main {
- public static void main(String[] args) throws IOException {
- URLConnection conn = new URL("http://streams.ilovemusic.de/iloveradio6.mp3").openConnection();
- InputStream is = conn.getInputStream();
- OutputStream out = new FileOutputStream(new File("C:/Users/rasah_s2z0ncs/Desktop/CwBw/abc.mp3"));
- byte[] buffer = new byte[4096];
- int len;
- Thread t = new AudioThread();
- t.start();
- while ((len =is.read(buffer)) > 0){
- out.write(buffer);
- System.out.println(len);
- }
- }
- private static class AudioThread extends Thread {
- @Override
- public void run(){
- try {
- sleep(2000);
- AudioPlayer.player.start(new AudioStream(new FileInputStream("C:/Users/rasah_s2z0ncs/Desktop/CwBw/abc.mp3")));
- } catch (InterruptedException | IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment