This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Reading From an Audio CD

 
Ranch Hand
Posts: 85
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I'm Finishing up my  java music player that is also a portfolio  project and  I wondered how I  can read from an audio CD in java. The java file class can read the file  data and send it to ffmpeg via opencv for java  and then write to the source data line for playing , unless the user skips songs too fast or tries to seek them. Then the  song refuses to play (due to buffer under runs I believe; it throws ffmpeg frame grabber execeptions) and it just keeps skipping tracks. File input stream was slightly better  but it  faced other problems and still had seeking problems. My latest idea was to cache the file on to the hard disk and  then play it. But not one of the four  file copy methods  I tried, Java Copy File – Stream, Java Copy File – java.nio.channels.FileChannel, Java Copy File – Apache Commons IO FileUtils, Java Copy File – Files class  was able to copy 100% of the file 100% of the time. They mostly transferred about 50-60% of it and then quit.  So how does one read from a CD in java? I'm running OSX 10.12 and all of the audio files appear up as AIFF files . I  would like to be able to have this work  for all major desktop platforms (OSX Windows, Linux) though.
 
Rancher
Posts: 144
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesse Matty wrote:So how does one read from a CD in java?


Most likely: not at all. The reason is the Compact Disc Digital Audio format: according to wikipedia, an audio-cd doesn't contain any computer readable filesystem and hence no files but only a TOC contain index meta data followed by a continous bitstream of audio encoded as 16 bit signed 2 track 41.100 Hz pcm audio. To be able to read such data needs to be able to read the TOC first, wich Java cannot as it simply doesn't allow such low-level access to a media (I can only confirm this for windows, unsure about unix - but I guess as unix allows access to anything by special virtual /dev filesystem it maybe can be done somehow). So, to read an audio-cd (at what makes a file explorer come up with pseudo-files) relies on the driver and OS api functions.
It can be broken down to: Playing a CD-DA is one of many things Java can't do out of the box without additional libs providing low-level access to OS api or device driver.
The only way this MAY work on unix could be if you are able to read the TOC you have to decode it (I guess there's some info about that out somewhere) wich then can be used to read the PCM stream - wich can be used with Javas audio system as PCM is the one low-level uncomprimated audio format Java understands without any additional filters.
 
Kristina Hansen
Rancher
Posts: 144
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know this is mostly "solved" as no reply followed, but I'd like to add is it's still relevant to the question and to my previous reply:
I was tasked with "reading from an audio cd" on x-mas eve as I was asked to rip a very old x-mas disc. As I knew I would need some ripper program on windows (unless I want to fiddle around with windows media player) I thought using linux might solve this issue. But it failed as hard as I thought how simple it might be. On linux you have to mount drives before you can read from them. But as already explained on my previous post: An audio cd does not have any filesystem - so it could not be mounted. Even try to access the disc drive itself with root only resulted in an I/O error. Luckly there're several ripper free available on the repos so it was just a matter of a quick google search wich grabber to use how. The rest was done by package manager.
Why I think this is important to add: In my last post I mentioned it might be possible on linux by just reading from the virtual block device file in /dev - but as I just learned myself that's not possible.
So, how ever it is possible for audio players to read audio cds, it's something low-level Java doesn't let you access without a native lib. Hence I have change my initial response to: You don't without JNI.
 
Get meta with me! What pursues us is our own obsessions! But not this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic