4

I would like to ask if there is any possibility to access the cdrom device via sound libraries in Java.

What I want to do is to mute CD Analog. I've searched using google for a long time, but there is no information about such an operation. I assume that this is trivial or very complex.

This simple code list my mixers:

try
{
    Mixer.Info [] mixerList = AudioSystem.getMixerInfo();
    for (Mixer.Info mixerInfo : mixerList)
    {
        System.out.println();
        System.out.println("MIXER: "+ mixerInfo.getName());
        Mixer mixer = AudioSystem.getMixer(mixerInfo);
        Line.Info[] li = mixer.getSourceLineInfo();
        System.out.println("LINES:");
        for (Line.Info info2 : li)
        {
            System.out.println(info2.toString());
        }

    }
} 
catch (Exception e)
{
    e.printStackTrace();
}

The output is:

MIXER: Primary Sound Driver
LINES:
interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
interface Clip supporting 8 audio formats, and buffers of at least 32 bytes

MIXER: Speakers (Realtek High Definition Audio)
LINES:
interface SourceDataLine supporting 8 audio formats, and buffers of at least 32 bytes
interface Clip supporting 8 audio formats, and buffers of at least 32 bytes

MIXER: Primary Sound Capture Driver
LINES:

MIXER: Desktop Microphone (Cinema - Mi
LINES:

MIXER: Microphone (Realtek High Defini
LINES:

MIXER: Port Speakers (Realtek High Definiti
LINES:

MIXER: Port Desktop Microphone (Cinema - Mi
LINES:
MICROPHONE source port

MIXER: Port Microphone (Realtek High Defini
LINES:
MICROPHONE source port

But there is no such device like cd analog. When I try obtaining a particular port from the mixer using Port.Info.COMPACT_DISC there is an exception no such device.

Can anybody assist me with this issue?

rainbow
  • 1,161
  • 3
  • 14
  • 29

1 Answers1

3

Have a look at java-avm library:

java-avm (Audio Video Media) is a Java API for accessing and controlling disc drives, particularly CD-ROM and CD-R(W) drives, removable drives, and loopback devices.

...

CD-ROM Specific:

  • Control CD-Audio playback with volume adjustment.
David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
  • I want to use 3rd party libraries only if there is no other way. – rainbow Jan 28 '13 at 12:29
  • @user2018059 I know of no other way (except maybe through JavaScript media api). Also libraries are not bad, they are actually helpful and in most cases do it better than we could by ourself as it has had some time for refinement across many platforms.... You could see how the 3rd party library does it, but most likely uses JNI. – David Kroukamp Jan 28 '13 at 12:48
  • 1
    See also [Can Java Sound be used to control the system volume?](http://stackoverflow.com/q/14301618/418556) While that is slightly different task to muting the CD, Java Sound would likely be as useful at that as it was at altering the system volume. Therefore I 2nd the suggestion of @DavidKroukamp - use a 3rd party API. – Andrew Thompson Jan 28 '13 at 12:54
  • It seems that David's advice is inevitable. But how to use it? I am confused. As i understand i need to download this package and built it into jar files. Then import into my project. Am i right? David did you used it earlier? – rainbow Jan 28 '13 at 13:07