duh ikal
duh ikal

Reputation: 162

How to record audio device with JMF?

So for me to record audio from a microphone from a computer, i would need to use an CaptureDeviceManager to return a list of available devices installed on the computer system. This is possible by calling getDeviceList(Format format). However for me to create an instance of Format i would need to specify an encoding String inside constructor new Format(String encoding). I'm not sure what that encoding would be since i just want to return a list of all available devices. And the getDeviceList() method returns an empty Vector.

The API also says this about the method getDeviceList(Format format):

 If no Format is specified, this method returns a list of CaptureDeviceInfo 
 objects for all of the available capture devices.

However there is only one getDeviceList() method that requires a format.

Upvotes: 2

Views: 154

Answers (2)

gpasch
gpasch

Reputation: 2682

You can use first

Vector devs = CaptureDeviceManager.getDeviceList(null)

Then you can use

devs = CaptureDeviceManager.getDeviceList(fmts);

where fmts is

AudioFormat fmts=getAudioFormat();

and

private AudioFormat getAudioFormat() {
    double sampleRate = 44100;
    int sampleSizeInBits = 16;
    int channels = 2;
    boolean signed = true;
    boolean bigEndian = true;
    return new AudioFormat(AudioFormat.LINEAR, sampleRate, sampleSizeInBits, channels); 
  }

It used to work for me.

Upvotes: 1

Phil Freihofner
Phil Freihofner

Reputation: 7910

I don't know that JMF is the tool you want to be using here. Maybe there's info about your context that is pertinent. JMF is pretty old tech. If you want to inspect audio resources using Java, the main techniques are explained in the tutorial Accessing Audio System Resources.

The tutorial includes a code example for inspecting ports/lines to see if they support microphones. The methods exposed by the javax.sound.sampled.AudioSystem class are extensive and flexible.

Upvotes: 1

Related Questions