Hallo,
ich versuche gerade mit JAAD AAC-Streams abzuspielen. Dafür habe ich folgende Mehtode:
Der Stream hinter der URL lautet:
http://streams.bigfm.de/bigfm-deutschland-128-aac?usid=0-0-H-A-D-30
Ich übergebe der Methode ein FileArray der Größe 1. Leider kommt der Code nicht weiter als cont = new MP4Container(in).
Wenn ich mir über den auskommentierten BufferedReader den Stream der URL ausgeben lasse, bekomme ich Daten (allerdings stellt die Konsole nur kryptische Zeichen da, was ich bei AAC mal als 'positiv' werte).
Wenn ich dem MP4-Container eine MP4-Datei übegebe (als RandomAccessFile), funktioniert es. Ich höre da zwar auch kein Audio, aber ich komme immerhin in die while-Schleife.
Laut der Doku von JAAD akzeptiert der Mp4-Container aber auch einen InputStream.
Kennt sich jemand mit JAAD aus und kann hier weiterhelfen? Oder kennt jemand eine ander Möglichkeit AAC aus einem Webstream abzuspielen?
ich versuche gerade mit JAAD AAC-Streams abzuspielen. Dafür habe ich folgende Mehtode:
Java:
public void play(File[] files) {
try {
// for-next loop to play each titel from the playlist once
for (currentTrack = 0; currentTrack < files.length; currentTrack++) {
InputStream in = url.openStream();
// InputStreamReader isr = new InputStreamReader(in);
// BufferedReader br = new BufferedReader(isr);
// String zeile = br.readLine();
// while (zeile != null) {
// System.err.println(zeile);
// zeile = br.readLine();
// }
cont = new MP4Container(in);// open titel with random access
movie = cont.getMovie(); // get content from container,
List<Track> content = movie.getTracks();
System.err.println(content.isEmpty());
if (content.isEmpty())// check if container HAS content
throw new Exception("content is empty"); // if so,
track = (AudioTrack) movie.getTracks().get(0);// grab first track and set the audioformat
af = new AudioFormat(track.getSampleRate(), track.getSampleSize(), track.getChannelCount(), true, true);
line = AudioSystem.getSourceDataLine(af); // get a DataLine from the AudioSystem
line.open(); // open and
line.start(); // start it
dec = new Decoder(track.getDecoderSpecificInfo());
buf = new SampleBuffer();
while (track.hasMoreFrames()) // while we have frames left
{
frame = track.readNextFrame(); // read next frame,
dec.decodeFrame(frame.getData(), buf); // decode it and put into the buffer
b = buf.getData(); // write the frame data from the buffer to our byte-array
line.write(b, 0, b.length); // and from there write the byte array into our open AudioSystem DataLine
while (paused) // check if we should pause
{
Thread.sleep(500); // if yes, stay half a second
if (Thread.interrupted()) // check if we should stop possibly
{
line.close(); // if yes, close line and
return; // exit thread
}
}
if (Thread.interrupted()) // if not in pause, still check on each frame if we should
{ // stop. If so
line.close(); // close line and
return; // exit thread
}
}
line.close(); // after titel is over, close line
if (loop) // if we should loop current titel, set currentTrack -1,
currentTrack--; // as on bottom of for-next it get's +1 and so the same titel get's played again
else if (repeat && (currentTrack == files.length - 1)) // else check if we are at the end of the playlist
currentTrack = -1; // and should repeat the whole list. If so, set currentTrack -1, so it get's 0 on for-next bottom
}
} catch (LineUnavailableException | IOException | InterruptedException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
Der Stream hinter der URL lautet:
http://streams.bigfm.de/bigfm-deutschland-128-aac?usid=0-0-H-A-D-30
Ich übergebe der Methode ein FileArray der Größe 1. Leider kommt der Code nicht weiter als cont = new MP4Container(in).
Wenn ich mir über den auskommentierten BufferedReader den Stream der URL ausgeben lasse, bekomme ich Daten (allerdings stellt die Konsole nur kryptische Zeichen da, was ich bei AAC mal als 'positiv' werte).
Wenn ich dem MP4-Container eine MP4-Datei übegebe (als RandomAccessFile), funktioniert es. Ich höre da zwar auch kein Audio, aber ich komme immerhin in die while-Schleife.
Laut der Doku von JAAD akzeptiert der Mp4-Container aber auch einen InputStream.
Kennt sich jemand mit JAAD aus und kann hier weiterhelfen? Oder kennt jemand eine ander Möglichkeit AAC aus einem Webstream abzuspielen?