• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Reading From an Audio CD

Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • 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.
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • 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.
Don't touch me. And dont' touch this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!