Accessing the tracks on a CD

Is there a pure-java way to get tracks from a CD? Not playing them, just getting the bytes.I know this can be done through JNI, but I would like to know if there is a pure java way.
[195 byte] By [jadespirita] at [2007-11-26 22:16:33]
# 1

As far as I know, audio tracks are .WAV files, so you can read them the same way you read normal files from a CD.

eg

public static void main(String[] args) {

File dir = new File("D:\\"); //on linux I think you must mount the CD first

String[] tracks = dir.list();

for(String i : tracks) {

System.out.println(i);

}

}

Ruly-o_Oa at 2007-7-10 11:09:57 > top of Java-index,Java Essentials,Java Programming...
# 2
http://java.sun.com/docs/books/tutorial/sound/index.htmlCheck out the Java Sound API.I believe that you should be able to capture streaming audio bits with different utilities in this package.
maple_shafta at 2007-7-10 11:09:57 > top of Java-index,Java Essentials,Java Programming...
# 3

> As far as I know, audio tracks are .WAV files, so you

> can read them the same way you read normal files from

> a CD.

Then you dont know! just kidding ; )

CD Audio is actually in the Red Book Audio Standard

http://en.wikipedia.org/wiki/Red_Book_(audio_CD_standard)

It is essentially a WAV format in 16 44100.

However reading it from the CD is in NO WAY equivalent to

reading a file from the harddrive.

It requires OS dependent native code.

You need to google how to open .cda (cdda) files.

There are libraries out there for this that utilize JNI but they are

wholly platform dependent.

TuringPesta at 2007-7-10 11:09:57 > top of Java-index,Java Essentials,Java Programming...
# 4

> ...

> Then you dont know! just kidding ; )

>

> CD Audio is actually in the Red Book Audio Standard

> http://en.wikipedia.org/wiki/Red_Book_(audio_CD_standard)

>

> It is essentially a WAV format in 16 44100.

> However reading it from the CD is in NO WAY

> equivalent to reading a file from the harddrive.

> It requires OS dependent native code.

>

> You need to google how to open .cda (cdda) files.

> There are libraries out there for this that utilize

> JNI but they are

> wholly platform dependent.

@OP: so the answer to your question is: no.

; )

prometheuzza at 2007-7-10 11:09:57 > top of Java-index,Java Essentials,Java Programming...
# 5
> @OP: so the answer to your question is: no.> ; )haha, i reacted so quickly to the first reply i didnt even read the OPs question. yea, the answer = a definitive no.
TuringPesta at 2007-7-10 11:09:57 > top of Java-index,Java Essentials,Java Programming...
# 6

If you look at the javax.sound.sampled package you'll find for example this class http://java.sun.com/javase/6/docs/api/javax/sound/sampled/Port.Info.html

which does suggest that you can use the sound API to access the tracks on a cd (there's a static field named COMPACT_DISC).

So I would say that the answer is in fact yes, you can create a stream to read the bytes off a cd, but I can't say for sure, since I haven't used the API myself.

You would probably have more luck at the sound forum.

#

duckbilla at 2007-7-10 11:09:57 > top of Java-index,Java Essentials,Java Programming...
# 7
Ok people, thanks for snappy answers :)
jadespirita at 2007-7-10 11:09:57 > top of Java-index,Java Essentials,Java Programming...
# 8

> If you look at the javax.sound.sampled package you'll

> find for example this class

> http://java.sun.com/javase/6/docs/api/javax/sound/samp

> led/Port.Info.html

> which does suggest that you can use the sound API to

> access the tracks on a cd (there's a static field

> named COMPACT_DISC).

>

> So I would say that the answer is in fact yes,

> you can create a stream to read the bytes off a cd,

> but I can't say for sure, since I haven't used the

> API myself.

>

> You would probably have more luck at the sound

> forum.

>

> #

The java media classes use native code (just like all i/o operations). So the answer to the OP question if s/he can read the bytes from an audio cd with pure Java code, is no.

prometheuzza at 2007-7-10 11:09:57 > top of Java-index,Java Essentials,Java Programming...
# 9

> So I would say that the answer is in fact yes,

> you can create a stream to read the bytes off a cd,

> but I can't say for sure, since I haven't used the

> API myself.

using a PORT would require grabbing the bytes in real time as

it was playing. i dont believe there is random access or control

either.

using a library to read cdda "files" (theyre actually 32bit? system

shortcuts) you could do random access and much faster bulk reads

from the cd (for encoding and such).

if you read the tritonus and cdparanoia (linux only i believe) pages

youll see that cdda reading is a bit involved.

http://tritonus.org/plugins.html

ps - the point being, there are MANY opens source windows command line cd extractors / accessors. you could easily call them with Runtime or port with them with JNI.

TuringPesta at 2007-7-10 11:09:57 > top of Java-index,Java Essentials,Java Programming...
# 10

> The java media classes use native code (just like all

> i/o operations). So the answer to the OP question if

> s/he can read the bytes from an audio cd with pure

> Java code, is no.

True but the OP need not write any JNI code himself. So in that sense he can accomplish his task in "pure java". =)

#

duckbilla at 2007-7-10 11:09:57 > top of Java-index,Java Essentials,Java Programming...
# 11
> ...> True but the OP need not write any JNI code himself.> So in that sense he can accomplish his task in> "pure java". =)> > #Yes, that might well be the OP's intention.; )
prometheuzza at 2007-7-10 11:09:57 > top of Java-index,Java Essentials,Java Programming...
# 12

> > The java media classes use native code (just like

> all

> > i/o operations). So the answer to the OP question

> if

> > s/he can read the bytes from an audio cd with pure

> > Java code, is no.

>

> True but the OP need not write any JNI code himself.

> So in that sense he can accomplish his task in

> "pure java". =)

>

> #

Wrong. The OP said " Not playing them, just getting the bytes".

You CAN NOT do that with PORT.

The OP WILL need a platform dependent natively written program.

Sure he can invoke it with Runtime but he would most likely have to

extract the entire track to a wav file and then read from the wav file.

TuringPesta at 2007-7-10 11:09:57 > top of Java-index,Java Essentials,Java Programming...
# 13
> Wrong. The OP said " Not playing them, just getting> the bytes".> You CAN NOT do that with PORT.Roger that. Good to know.#
duckbilla at 2007-7-10 11:09:57 > top of Java-index,Java Essentials,Java Programming...
# 14

> The java media classes use native code (just like all

> i/o operations). So the answer to the OP question if

> s/he can read the bytes from an audio cd with pure

> Java code, is no.

With this argumentation you could say that no files can be read from a CD (or a hard disk for that matter) in pure java because of the native code involved with I/O, moreover there can be no pure java code at all, given the fact we need a JVM.

BIJ001a at 2007-7-10 11:09:57 > top of Java-index,Java Essentials,Java Programming...
# 15

> ...

> With this argumentation you could say that no files

> can be read from a CD (or a hard disk for that

> matter) in pure java because of the native code

> involved with I/O, moreover there can be no pure java

> code at all, given the fact we need a JVM.

You could say that, yes. One could also say that everything that only exists in the JVM is pure Java code (I know: vague terminology, hope you get my point).

Note that I said this to make it clear to the OP that a lot of core classes in the JDK make use of native code.

prometheuzza at 2007-7-21 18:37:27 > top of Java-index,Java Essentials,Java Programming...
# 16
WOW! Thank you all for such elaborate answers! You helped a lot! :)
jadespirita at 2007-7-21 18:37:27 > top of Java-index,Java Essentials,Java Programming...