Note that there are some explanatory texts on larger screens.

plurals
  1. PORecord streaming audio in java?
    primarykey
    data
    text
    <p>I'm trying to set up a program to record a portion of an internet audio stream, and save it to a file (preferably mp3 or wav). I've looked everywhere and I can't find any decent ways to do this. I found two different libraries that seemed like they'd work (NativeBass and Xuggle), but neither supported 64-bit windows which is what I need.</p> <p>Does anyone know of any simple ways to save a portion of an internet audio stream using java? (If it's important, it's an "audio/mpeg" stream). </p> <p>EDIT: Okay, I found a way that seems to work. But I still have a question</p> <pre><code>import java.net.URLConnection; import java.net.URL; import java.io.InputStream; import java.io.OutputStream; import java.io.FileOutputStream; import java.io.File; public class Test{ public static void main (String[] args){ try{ URLConnection conn = new URL("http://streamurl.com/example").openConnection(); InputStream is = conn.getInputStream(); OutputStream outstream = new FileOutputStream(new File("C:/Users/Me/Desktop/output.mp3")); byte[] buffer = new byte[4096]; int len; long t = System.currentTimeMillis(); while ((len = is.read(buffer)) &gt; 0 &amp;&amp; System.currentTimeMillis() - t &lt;= 5000) { outstream.write(buffer, 0, len); } outstream.close(); } catch(Exception e){ System.out.print(e); } } } </code></pre> <p>I got most of this from another answer on here after a bit more searching. However, one thing I'm trying to do is only record for a certain amount of time. As you can see above, I tried to only record a 5 second interval. </p> <pre><code>long t = System.currentTimeMillis(); while ((len = is.read(buffer)) &gt; 0 &amp;&amp; System.currentTimeMillis() - t &lt;= 5000) { </code></pre> <p>However, for one reason or another, the recorded audio isn't 5 seconds long, it's 16. Does anyone know how to be more precise in limiting the length of the stream? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload